Improve fish completion (#376, #534)#535
Merged
Merged
Conversation
A generated fish script didn't complete an option after an argument. The cause is the generated fish script doesn't accept an input text which already has arguments. For example, when the input is `repeat -`, the script can complete `--count`, but when the text is `repeat foo -`, the script cannot complete `repeat foo --count`, because the input text already has the argument "foo". To fix the issue, `FishCompletionsGenerator` got a capability that can accept a text which has arguments.
natecook1000
requested changes
Jan 5, 2023
Member
natecook1000
left a comment
There was a problem hiding this comment.
Thanks so much, @mtj0928! Just a couple of small changes below, and could you update the fish test expectation for testMath_CompletionScript()?
| results.append((commandChain, suggestion)) | ||
| } | ||
| } | ||
| private enum FishScriptBuilder { |
Member
There was a problem hiding this comment.
I don't think we need a new namespace here — can these just be fileprivate static members of FishCompletionsGenerator?
Comment on lines
+66
to
+67
| var results = names | ||
| .map{ $0.asFishSuggestion } |
Member
There was a problem hiding this comment.
Nit:
Suggested change
| var results = names | |
| .map{ $0.asFishSuggestion } | |
| var results = names.map { $0.asFishSuggestion } |
Contributor
Author
|
@natecook1000 Thank you for your review! |
Member
|
@swift-ci Please test |
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A generated fish script didn't complete an option after an argument.
The cause is the generated fish script doesn't accept an input text which already has arguments.
For example, when the input is
repeat -, the script can complete--count, but when the text isrepeat foo -, the script cannot completerepeat foo --count, because the input text already has the argument "foo".To fix the issue, I implemented the following steps.
Preprocess for the subcommand.
To support options of the root command like
math --version add,--versionis removed by_swift_{command name}_preprocessor.Decide a command.
In a case when a command has some subcommands like
math stats average 1 10 100 --kind mean, we need to decide the target command. (In the example case, the target command isaverage.)To decide it, the newly generated script receives
expected commandandsubcommands.(e,g,)
statsor not.expected command=math statssubcommands=average stdev quantiles helpaverageor not.expected command=math stats averagesubcommandsis empty (averagedoesn't have any subcommands.)`When the input has the expected command, and a text after the expected command is not the subcommand, the newly generated script decide the command is a target command, and suggest options for the target command.
Related issues
Checklist