Don't automatically remove common prefixes from suggestions
This commit is contained in:
parent
482e8601da
commit
182168acd5
4 changed files with 17 additions and 13 deletions
|
@ -43,8 +43,7 @@ public class SuggestionsBuilder {
|
||||||
if (text.equals(remaining)) {
|
if (text.equals(remaining)) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
final String prefix = Strings.commonPrefix(text, remaining);
|
result.add(new Suggestion(StringRange.between(start, input.length()), text));
|
||||||
result.add(new Suggestion(StringRange.between(start + prefix.length(), input.length()), text.substring(prefix.length())));
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,8 +49,8 @@ public class CommandSuggestionsTest {
|
||||||
|
|
||||||
final Suggestions result = subject.getCompletionSuggestions(subject.parse("b", source)).join();
|
final Suggestions result = subject.getCompletionSuggestions(subject.parse("b", source)).join();
|
||||||
|
|
||||||
assertThat(result.getRange(), equalTo(StringRange.at(1)));
|
assertThat(result.getRange(), equalTo(StringRange.between(0, 1)));
|
||||||
assertThat(result.getList(), equalTo(Lists.newArrayList("ar", "az")));
|
assertThat(result.getList(), equalTo(Lists.newArrayList("bar", "baz")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -80,8 +80,8 @@ public class CommandSuggestionsTest {
|
||||||
final ParseResults<Object> parse = subject.parse("parent b", source);
|
final ParseResults<Object> parse = subject.parse("parent b", source);
|
||||||
final Suggestions result = subject.getCompletionSuggestions(parse).join();
|
final Suggestions result = subject.getCompletionSuggestions(parse).join();
|
||||||
|
|
||||||
assertThat(result.getRange(), equalTo(StringRange.at(8)));
|
assertThat(result.getRange(), equalTo(StringRange.between(7, 8)));
|
||||||
assertThat(result.getList(), equalTo(Lists.newArrayList("ar", "az")));
|
assertThat(result.getList(), equalTo(Lists.newArrayList("bar", "baz")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -104,8 +104,8 @@ public class CommandSuggestionsTest {
|
||||||
final ParseResults<Object> parse = subject.parse("redirect s", source);
|
final ParseResults<Object> parse = subject.parse("redirect s", source);
|
||||||
final Suggestions result = subject.getCompletionSuggestions(parse).join();
|
final Suggestions result = subject.getCompletionSuggestions(parse).join();
|
||||||
|
|
||||||
assertThat(result.getRange(), equalTo(StringRange.at(10)));
|
assertThat(result.getRange(), equalTo(StringRange.between(9, 10)));
|
||||||
assertThat(result.getList(), equalTo(Lists.newArrayList("ub")));
|
assertThat(result.getList(), equalTo(Lists.newArrayList("sub")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -21,8 +21,8 @@ public class SuggestionsBuilderTest {
|
||||||
@Test
|
@Test
|
||||||
public void suggest_appends() {
|
public void suggest_appends() {
|
||||||
final Suggestions result = builder.suggest("world!").build();
|
final Suggestions result = builder.suggest("world!").build();
|
||||||
assertThat(result.getList(), equalTo(Lists.newArrayList("orld!")));
|
assertThat(result.getList(), equalTo(Lists.newArrayList("world!")));
|
||||||
assertThat(result.getRange(), equalTo(StringRange.at(7)));
|
assertThat(result.getRange(), equalTo(StringRange.between(6, 7)));
|
||||||
assertThat(result.isEmpty(), is(false));
|
assertThat(result.isEmpty(), is(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,9 +53,14 @@ public class LiteralCommandNodeTest extends AbstractCommandNodeTest {
|
||||||
@Test
|
@Test
|
||||||
public void testParseSimilar() throws Exception {
|
public void testParseSimilar() throws Exception {
|
||||||
final StringReader reader = new StringReader("foobar");
|
final StringReader reader = new StringReader("foobar");
|
||||||
|
try {
|
||||||
node.parse(reader, contextBuilder);
|
node.parse(reader, contextBuilder);
|
||||||
assertThat(reader.getRemaining(), equalTo("bar"));
|
fail();
|
||||||
// This should succeed, because it's the responsibility of the dispatcher to realize there's trailing text
|
} 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
|
@Test
|
||||||
|
|
Loading…
Reference in a new issue