Don't automatically remove common prefixes from suggestions

This commit is contained in:
Nathan Adams 2018-02-05 15:51:48 +01:00
parent 482e8601da
commit 182168acd5
4 changed files with 17 additions and 13 deletions

View file

@ -43,8 +43,7 @@ public class SuggestionsBuilder {
if (text.equals(remaining)) {
return this;
}
final String prefix = Strings.commonPrefix(text, remaining);
result.add(new Suggestion(StringRange.between(start + prefix.length(), input.length()), text.substring(prefix.length())));
result.add(new Suggestion(StringRange.between(start, input.length()), text));
return this;
}

View file

@ -49,8 +49,8 @@ public class CommandSuggestionsTest {
final Suggestions result = subject.getCompletionSuggestions(subject.parse("b", source)).join();
assertThat(result.getRange(), equalTo(StringRange.at(1)));
assertThat(result.getList(), equalTo(Lists.newArrayList("ar", "az")));
assertThat(result.getRange(), equalTo(StringRange.between(0, 1)));
assertThat(result.getList(), equalTo(Lists.newArrayList("bar", "baz")));
}
@Test
@ -80,8 +80,8 @@ public class CommandSuggestionsTest {
final ParseResults<Object> parse = subject.parse("parent b", source);
final Suggestions result = subject.getCompletionSuggestions(parse).join();
assertThat(result.getRange(), equalTo(StringRange.at(8)));
assertThat(result.getList(), equalTo(Lists.newArrayList("ar", "az")));
assertThat(result.getRange(), equalTo(StringRange.between(7, 8)));
assertThat(result.getList(), equalTo(Lists.newArrayList("bar", "baz")));
}
@Test
@ -104,8 +104,8 @@ public class CommandSuggestionsTest {
final ParseResults<Object> parse = subject.parse("redirect s", source);
final Suggestions result = subject.getCompletionSuggestions(parse).join();
assertThat(result.getRange(), equalTo(StringRange.at(10)));
assertThat(result.getList(), equalTo(Lists.newArrayList("ub")));
assertThat(result.getRange(), equalTo(StringRange.between(9, 10)));
assertThat(result.getList(), equalTo(Lists.newArrayList("sub")));
}
@Test

View file

@ -21,8 +21,8 @@ public class SuggestionsBuilderTest {
@Test
public void suggest_appends() {
final Suggestions result = builder.suggest("world!").build();
assertThat(result.getList(), equalTo(Lists.newArrayList("orld!")));
assertThat(result.getRange(), equalTo(StringRange.at(7)));
assertThat(result.getList(), equalTo(Lists.newArrayList("world!")));
assertThat(result.getRange(), equalTo(StringRange.between(6, 7)));
assertThat(result.isEmpty(), is(false));
}

View file

@ -53,9 +53,14 @@ public class LiteralCommandNodeTest extends AbstractCommandNodeTest {
@Test
public void testParseSimilar() throws Exception {
final StringReader reader = new StringReader("foobar");
node.parse(reader, contextBuilder);
assertThat(reader.getRemaining(), equalTo("bar"));
// This should succeed, because it's the responsibility of the dispatcher to realize there's trailing text
try {
node.parse(reader, contextBuilder);
fail();
} catch (final CommandSyntaxException ex) {
assertThat(ex.getType(), is(LiteralCommandNode.ERROR_INCORRECT_LITERAL));
assertThat(ex.getData(), is(ImmutableMap.<String, Object>of("expected", "foo")));
assertThat(ex.getCursor(), is(0));
}
}
@Test