You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Completion definition prevent valid command from executing #6020
When I use the completion definitions found in nu_scripts/custom-completions/npm/npm-completions.nu, that prevents me from running perfectly valid commands.
Apparently the syntax definition prevents nu from parsing the command correctly. I would have expected that this information would only be used for completion/help/info generation. If I have typed a command I would have expected nu to obey it.
Seems like a lot of users feel confused about this. The reason why the command failed is that the npm is being treated as pre-defined internal command instead of external during parsing. This brings us to a question → Regarding the custom commands, by default, should they be internal or external: My understanding is they are external, the reason is simple - They are not built-in
I think they are their own category as is_custom but you may be right that they could be treated as external. Also custom completions kind of play in this arena too but don't have their own category.
I did take a look at the parser, seems like there is a bug or missing part with regard to the custom command. The export extern <command> is a KnownExternal(trait object of Command), but the parser just handle it as Internal. It should be ok to just add some conditional checks without big changes. For the completion, i will take a look at them too
This is actually not a Nushell problem, but just the completion definition was written such that it requires the positional argument instead of making it optional. Changing
command: string@"nu-complete npm"
to
command?: string@"nu-complete npm"
in the npm definition should solve the problem. I'll close this issue as it does not seem to show a problem in Nushell itself.
The npm was an example, this issue is about the general problem as indicated in the title: the fact that completion syntaxes will not always reflect the syntax of all (versions of) a certain tool correctly and how nushell deals with that. Perhaps this issue should stay open until the general problem is addressed in a satisfactory manner?
The issue is worded such that it sounds npm-specific. #7527 will be merged in after the 0.73 release, you're welcome to try it and see if it helps. Unfortunately, "commands are not parsed correctly" and "general problem is addressed" are very generic statements that are not actionable. If you still find some problems, feel free to formulate them concretely, what solutions you'd imagine and open a new issue.
The issue is worded such that it sounds npm-specific.
I did not intend it to be, so my apologies if I didn't formulate unambiguously enough.
Unfortunately, "commands are not parsed correctly" and "general problem is addressed" are very generic statements that are not actionable. If you still find some problems, feel free to formulate them concretely, what solutions you'd imagine and open a new issue.
I was referring to my expectations stated in the OP:
I would have expected that this information would only be used for completion/help/info generation.
It seemed undesirable to me that a completion script, designed to help the user by providing completions, would also prevent commands from executing if they don't meet the syntax form as described in the completion script. I felt that a user should be able to execute whatever they want and not be held back by a completion script. I don't use completion scripts at all for this reason currently. I know about the ^ workaround but it's too annoying.
This actually sounds like it exactly addresses the issue I described, if it applies all completion scripts by default, which I think it does because it applies to all extern definitions.
I will send a pull request to patch it. However, it does seem like the fall-through mechanism introduced in #7527 could or should be extended to cover this case?
Activity
fdncred commentedon Jul 12, 2022
Agreed. Custom Completions need to be tweaked a bit. My way around this, for now, is to do
^npm.Kangaxx-0 commentedon Jul 13, 2022
Seems like a lot of users feel confused about this. The reason why the command failed is that the
npmis being treated as pre-definedinternalcommand instead ofexternalduringparsing. This brings us to a question → Regarding the custom commands, by default, should they beinternalorexternal: My understanding is they areexternal, the reason is simple - They are not built-infdncred commentedon Jul 13, 2022
I think they are their own category as is_custom but you may be right that they could be treated as external. Also custom completions kind of play in this arena too but don't have their own category.
Kangaxx-0 commentedon Jul 15, 2022
I did take a look at the parser, seems like there is a bug or missing part with regard to the custom command. The
export extern <command>is a KnownExternal(trait object of Command), but the parser just handle it as Internal. It should be ok to just add some conditional checks without big changes. For the completion, i will take a look at them tooCAD97 commentedon Jul 24, 2022
Catching incorrect usage is nice if you can verify that the nu definition is accurate and complete.
It may make sense to default to permissive, but the strict behavior should be available.
A simple syntax option to get a permissive extern is to have a
...parameter with the semantics of allowing whatever captured content.kubouch commentedon Dec 19, 2022
This is actually not a Nushell problem, but just the completion definition was written such that it requires the positional argument instead of making it optional. Changing
to
in the npm definition should solve the problem. I'll close this issue as it does not seem to show a problem in Nushell itself.
chtenb commentedon Dec 20, 2022
The npm was an example, this issue is about the general problem as indicated in the title: the fact that completion syntaxes will not always reflect the syntax of all (versions of) a certain tool correctly and how nushell deals with that. Perhaps this issue should stay open until the general problem is addressed in a satisfactory manner?
kubouch commentedon Dec 20, 2022
The issue is worded such that it sounds
npm-specific. #7527 will be merged in after the 0.73 release, you're welcome to try it and see if it helps. Unfortunately, "commands are not parsed correctly" and "general problem is addressed" are very generic statements that are not actionable. If you still find some problems, feel free to formulate them concretely, what solutions you'd imagine and open a new issue.chtenb commentedon Dec 20, 2022
I did not intend it to be, so my apologies if I didn't formulate unambiguously enough.
I was referring to my expectations stated in the OP:
I would have expected that this information would only be used for completion/help/info generation.It seemed undesirable to me that a completion script, designed to help the user by providing completions, would also prevent commands from executing if they don't meet the syntax form as described in the completion script. I felt that a user should be able to execute whatever they want and not be held back by a completion script. I don't use completion scripts at all for this reason currently. I know about the
^workaround but it's too annoying.This actually sounds like it exactly addresses the issue I described, if it applies all completion scripts by default, which I think it does because it applies to all
externdefinitions.chtenb commentedon Mar 4, 2023
Today I updated my nushell installation and checked this out. I think the behavior has improved a lot! Thanks for that.
However, the example given in the OP still does not work:
Is this something that can be fixed in the completion definition here?
https://github.com/nushell/nu_scripts/blob/main/custom-completions/npm/npm-completions.nu
For the record, if I pass something rubbish, the command correctly falls through to npm:
kubouch commentedon Mar 4, 2023
The
commandshould be optional:command?.chtenb commentedon Mar 5, 2023
I will send a pull request to patch it. However, it does seem like the fall-through mechanism introduced in #7527 could or should be extended to cover this case?
fdncred commentedon Mar 5, 2023
Indeed. We need to fix the fall through. I would love to see that improved.