Use contains instead of startsWith for context tab completions

This commit is contained in:
Luck 2020-05-27 10:43:30 +01:00
parent d5ac45d230
commit 4a049ca732
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
3 changed files with 22 additions and 1 deletions

View File

@ -49,6 +49,18 @@ public interface CompletionSupplier {
return partial -> stringsSupplier.get().filter(TabCompleter.startsWithIgnoreCase(partial)).collect(Collectors.toList());
}
static CompletionSupplier contains(String... strings) {
return contains(() -> Arrays.stream(strings));
}
static CompletionSupplier contains(Collection<String> strings) {
return contains(strings::stream);
}
static CompletionSupplier contains(Supplier<Stream<String>> stringsSupplier) {
return partial -> stringsSupplier.get().filter(TabCompleter.containsIgnoreCase(partial)).collect(Collectors.toList());
}
List<String> supplyCompletions(String partial);
}

View File

@ -107,4 +107,13 @@ public class TabCompleter {
};
}
static Predicate<String> containsIgnoreCase(String substring) {
return string -> {
if (string.length() < substring.length()) {
return false;
}
return string.toLowerCase().contains(substring.toLowerCase());
};
}
}

View File

@ -99,7 +99,7 @@ public final class TabCompletions {
int index = partial.indexOf('=');
if (index == -1) {
// cursor is specifying the key
return CompletionSupplier.startsWith(potentialContexts.toMap().keySet()).supplyCompletions(partial);
return CompletionSupplier.contains(potentialContexts.toMap().keySet()).supplyCompletions(partial);
}
// cursor is specifying the value