Reconsider how input buffer is tokenized

Fixes #85
This commit is contained in:
Eric Bottard
2017-06-19 09:35:11 +02:00
parent 7fd5390c29
commit 14b2401374
4 changed files with 45 additions and 37 deletions

View File

@@ -297,7 +297,7 @@ public class StandardParameterResolver implements ParameterResolver {
if (!set) {
if (unfinished == null) { // case 1 above
return commandsThatStartWithContextPrefix(methodParameter, context);
return argumentKeysThatStartWithContextPrefix(methodParameter, context);
} // case 2
else {
return valueCompletions(methodParameter, context);
@@ -306,9 +306,6 @@ public class StandardParameterResolver implements ParameterResolver {
else {
List<CompletionProposal> result = new ArrayList<>();
String prefix = context.currentWordUpToCursor() != null ? context.currentWordUpToCursor() : "";
// TODO: should not look at last word only, but everything after what was used for key
Object value = convertRawValue(parameterRawValue, methodParameter);
if (value instanceof Collection && ((Collection) value).size() == arity
|| (ObjectUtils.isArray(value) && Array.getLength(value) == arity)) {
@@ -320,7 +317,7 @@ public class StandardParameterResolver implements ParameterResolver {
if (parameterRawValue.positional()) {
// Case 4.1: There exists "--command foo" and user has typed "--comm" which (wrongly) got resolved as a positional param
result.addAll(commandsThatStartWithContextPrefix(methodParameter, context));
result.addAll(argumentKeysThatStartWithContextPrefix(methodParameter, context));
}
return result;
}
@@ -333,7 +330,7 @@ public class StandardParameterResolver implements ParameterResolver {
.findFirst().orElseGet(() -> Collections.emptyList());
}
private List<CompletionProposal> commandsThatStartWithContextPrefix(MethodParameter methodParameter, CompletionContext context) {
private List<CompletionProposal> argumentKeysThatStartWithContextPrefix(MethodParameter methodParameter, CompletionContext context) {
String prefix = context.currentWordUpToCursor() != null ? context.currentWordUpToCursor() : "";
return describe(methodParameter).keys().stream()
.filter(k -> k.startsWith(prefix))