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.
First of all, thanks for this awesome project, which has given me a lot of inspiration in the areas of terminal experience and smart completion. I have recently been trying to integrate it with Xterm.js. However, I encountered some issues while using it and reading the code.
What is the problem ?
When I type
npm run
, the terminal autocomplete returns the incorrect result "--registry", instead of the scripts in package.json or other run parameters.This behavior is somewhat strange, so I delved into the source code to look for the issue.
After spending some time debugging, the problem was finally located in the
genSubCommand
method of theruntime.ts
file.Here, we can see that when typing
npm run
, functiongenSubCommand
attempting to finds.name === 'run'
within ·parentCommand.subcommands· is unsuccessful, returningsubcommandIdx
is-1
.However, the judgment logic in the code is
SubCommand == null
, which obviously does not apply whensubCommand
is -1. As a result, it proceeds toparentCommand.subcommands.at(-1)
, effectively retrieving the last item in thesubcommands
list (the 69th item). Therefore, the output becomes--registry
instead of the correct result.How to Fix
By inspecting the contents of
parentCommand.subcommands
through the Debugger, it can be observed that thename
of asubCommand
might be an array of strings. And the type of subCommand also prove this.Therefore, we need to fix the find matching logic for
subCommands
to handle both arrays and strings during the match.Additionally, we also need to optimize the verification logic before and after the find match to handle exceptional cases.
After fix
After fix,
npm run
looks great !