Apply correct completion
- This commit fixes two issues. - Firstly complete with correct option as existing bug was to wrongly always complete with first option which used wrong provider. - Secondly filter out duplicate option proposals giving better result when options is already in place. - Fixes #495
This commit is contained in:
@@ -288,8 +288,8 @@ public class Shell {
|
||||
|
||||
// Try to complete arguments
|
||||
List<CommandOption> matchedArgOptions = new ArrayList<>();
|
||||
if (argsContext.getWords().size() > 0) {
|
||||
matchedArgOptions.addAll(matchOptions(registration.getOptions(), argsContext.getWords().get(0)));
|
||||
if (argsContext.getWords().size() > 0 && argsContext.getWordIndex() > 0 && argsContext.getWords().size() > argsContext.getWordIndex()) {
|
||||
matchedArgOptions.addAll(matchOptions(registration.getOptions(), argsContext.getWords().get(argsContext.getWordIndex() - 1)));
|
||||
}
|
||||
|
||||
List<CompletionProposal> argProposals = matchedArgOptions.stream()
|
||||
|
||||
@@ -38,11 +38,15 @@ public class RegistrationOptionsCompletionResolver implements CompletionResolver
|
||||
List<CompletionProposal> candidates = new ArrayList<>();
|
||||
context.getCommandRegistration().getOptions().stream()
|
||||
.flatMap(o -> Stream.of(o.getLongNames()))
|
||||
.map(ln -> new CompletionProposal("--" + ln))
|
||||
.map(ln -> "--" + ln)
|
||||
.filter(ln -> !context.getWords().contains(ln))
|
||||
.map(CompletionProposal::new)
|
||||
.forEach(candidates::add);
|
||||
context.getCommandRegistration().getOptions().stream()
|
||||
.flatMap(o -> Stream.of(o.getShortNames()))
|
||||
.map(ln -> new CompletionProposal("-" + ln))
|
||||
.map(ln -> "-" + ln)
|
||||
.filter(ln -> !context.getWords().contains(ln))
|
||||
.map(CompletionProposal::new)
|
||||
.forEach(candidates::add);
|
||||
return candidates;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user