[Console] Fix various completion edge cases #47432
Open
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.
Refs composer/composer#11029
There are two things I am trying to fix here:
composer require yiisoft/yii-[TAB]
works, butcomposer req yiisoft/yii-[TAB]
does not workcomposer up
suggetsupgrade update
but both are aliases to the same command, so I fixed it to make it always just suggest one name, which lets the shell complete tocomposer update
and then I can tab again to get more relevant completions.The fixes work almost.. I have one problem for which I need help from someone (maybe @wouterj?).
See the changes in CompleteCommand. The current code is doing smth like:
This is problematic because it breaks the 1st case I mentioned above, and it also is just fairly dodgy if you are trying to complete an arg with the command's name as input (e.g.
composer require require
) it will kinda stay stuck on suggesting the command's name even tho you are completing another arg here.So I am trying to change it to a flow like:
But it seems like CompletionInput does not work correctly there.. see these few examples from the completion debug output after I added some extra logging:
As you can see when the input is
c req|
it completes the command argument as it should, then withc require |
it also works as it should, detecting the space and moving tonone
completion. But then as soon as you have some more text it goes back to think it is completing the command argument and that makes no sense.I am too dumb or tired to figure out what's going on in the CompletionInput class or its tests, so I'd appreciate input there :)