Fix completion logic to only see words pertaining to args
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.shell2;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -78,4 +79,11 @@ public class CompletionContext {
|
||||
String currentWord = currentWord();
|
||||
return currentWord != null ? currentWord.substring(0, getPosition()) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a copy of this context, as if the first {@literal nbWords} were not present
|
||||
*/
|
||||
public CompletionContext drop(int nbWords) {
|
||||
return new CompletionContext(new ArrayList<String>(words.subList(nbWords, words.size())), wordIndex-nbWords, position);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,12 +154,13 @@ public class Shell implements CommandRegistry {
|
||||
return candidates;
|
||||
}
|
||||
|
||||
CompletionContext argsContext = context.drop(best.split(" ").length);
|
||||
// Try to complete arguments
|
||||
MethodTarget methodTarget = methodTargets.get(best);
|
||||
Method method = methodTarget.getMethod();
|
||||
return Arrays.stream(method.getParameters())
|
||||
.map(Utils::createMethodParameter)
|
||||
.flatMap(mp -> findResolver(mp).complete(mp, context).stream())
|
||||
.flatMap(mp -> findResolver(mp).complete(mp, argsContext).stream())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user