Summary: Currently, if we match "alnd" to "land" and "amend" equally (distance 2), we drop "land" with the other part of the rule. Stop doing that.
Test Plan:
Unit tests. Also:
```
$ arc alnd
Usage Exception: Unknown command 'alnd'. Try 'arc help'.
Did you mean:
amend
land
```
Reviewers: vrana
Reviewed By: vrana
CC: aran
Differential Revision: https://secure.phabricator.com/D5033
'ArcanistBaseXHPASTLinter' => 'lint/linter/ArcanistBaseXHPASTLinter.php',
'ArcanistBookmarkWorkflow' => 'workflow/ArcanistBookmarkWorkflow.php',
'ArcanistBranchWorkflow' => 'workflow/ArcanistBranchWorkflow.php',
+ 'ArcanistBritishTestCase' => 'configuration/__tests__/ArcanistBritishTestCase.php',
'ArcanistBrowseWorkflow' => 'workflow/ArcanistBrowseWorkflow.php',
'ArcanistBundle' => 'parser/ArcanistBundle.php',
'ArcanistBundleTestCase' => 'parser/__tests__/ArcanistBundleTestCase.php',
'ArcanistBaseXHPASTLinter' => 'ArcanistLinter',
'ArcanistBookmarkWorkflow' => 'ArcanistFeatureWorkflow',
'ArcanistBranchWorkflow' => 'ArcanistFeatureWorkflow',
+ 'ArcanistBritishTestCase' => 'ArcanistTestCase',
'ArcanistBrowseWorkflow' => 'ArcanistBaseWorkflow',
'ArcanistBundleTestCase' => 'ArcanistTestCase',
'ArcanistCallConduitWorkflow' => 'ArcanistBaseWorkflow',
// We haven't found a real command, alias, or unique prefix. Try similar
// spellings.
- $corrected = $this->correctCommandSpelling($command, $all, 2);
+ $corrected = self::correctCommandSpelling($command, $all, 2);
if (count($corrected) == 1) {
$console->writeErr(
pht(
return array_keys($is_prefix);
}
- private function correctCommandSpelling(
+ public static function correctCommandSpelling(
$command,
array $options,
$max_distance) {
asort($distances);
$best = min($max_distance, reset($distances));
foreach ($distances as $option => $distance) {
- if ($distance > $best || strlen($option) <= 2 * $distance) {
+ if ($distance > $best) {
+ unset($distances[$option]);
+ }
+ }
+
+ // Before filtering, check if we have multiple equidistant matches and
+ // return them if we do. This prevents us from, e.g., matching "alnd" with
+ // both "land" and "amend", then dropping "land" for being too short, and
+ // incorrectly completing to "amend".
+ if (count($distances) > 1) {
+ return array_keys($distances);
+ }
+
+ foreach ($distances as $option => $distance) {
+ if (strlen($option) <= 2 * $distance) {
unset($distances[$option]);
}
}
--- /dev/null
+<?php
+
+final class ArcanistBritishTestCase extends ArcanistTestCase {
+
+ public function testCompletion() {
+ $this->assertCompletion(
+ array('land', 'amend'),
+ 'alnd',
+ array('land', 'amend'));
+
+ $this->assertCompletion(
+ array('branch'),
+ 'brnach',
+ array('branch', 'browse'));
+
+ $this->assertCompletion(
+ array(),
+ 'test',
+ array('list', 'unit'));
+ }
+
+ private function assertCompletion($expect, $input, $commands) {
+ $result = ArcanistConfiguration::correctCommandSpelling(
+ $input,
+ $commands,
+ 2);
+
+ sort($result);
+ sort($expect);
+
+ $commands = implode(', ', $commands);
+
+ $this->assertEqual(
+ $expect,
+ $result,
+ "Correction of {$input} against: {$commands}");
+ }
+
+
+}