Repository navigation
make external signatures do not enforce flag checking - #7461
WindSoilder wants to merge 25 commits into
Conversation
|
Make as draft in case of restriction, need to find a way to pass unknown flags which take values |
|
Yeah, the |
|
I'm thinking about parsing it as internal call, if we get unknown flag error, then parse it as external call But it breaks our builtin auto completion :-( Not sure if we can change internal completor to make it right |
|
I think we might be going too fancy here. An idea: More complex example: With an external signature defined as This one would work for |
|
Thanks for your detailed instruction :-) There is a little question left: are |
|
Yeah, I'd say so. I'm not sure what would be the output if you had both. |
|
Actually, after chatting about it a bit, we realized the |
Hi, should we enable this feature only if we specify |
|
Let's just enable it by default when the signature is marked as a known external without requiring |
…n of parse_internal doesn't compatible with completion
|
Sorry for the relative large diff, I've updated |
|
Cool, I'll look into it when I have the time. In the meanwhile, could you also enable it for the |
|
Sure, I'll take a look how |
|
But here is a limitation: we can't pass So here is the result: Still show help message of exec command, but I think it's fine. |
…me from parse_known_extern_call to parse_internal_call_loosely
|
I tried the PR and it does not seem to be working correctly. On Linux, running returns while the output of is To me, the logic seems too complicated. I think the the unknown flags shouldn't be parsed as flags at all and re-creating them like you do also seems too fragile. An example how the logic could be is:
You should be able to weave this into the existing code without creating a new |
|
Thanks for your feedback! It's a really good test case :-D
I've tried to do with this way firstly, but sadly found that it breaks auto-completion for known extern, because And if I make it into current |
|
the issue of Removes some duplicate code in Sorry for that I have no idea how to make them into one |
|
Could you give an example how the completion failed with the method I described? I'm still hesitant landing it because of the added complexity to the parser for only a relatively minor change. I'll try some experiments myself and see if I can make it simpler. |
Oh, sorry, after apply this change, I think completion works for current design again...I'll revert some changes back again and see if it's actually working |
|
@WindSoilder I managed to find a relatively simple solution, see the linked PR above. It mostly works, except the |
|
Thanks! I'll take a look there |
|
Closing this infavor of #7527 |
Description
The pr is based on #6567 made by @merelymyself
Fixes #4659. Fixes #6020. Kind of Fixes #5103. Fixes #5294. Fixes #6124
User-Facing Changes
About the change
It's a little big change, because auto-completion makes some assumption on
parsefunction, which is incompatible to fall-through logic. In detail, based on user input, it relys onparsefunction returns error on UnknownFlag, for short flag, it may returns an extra-aFlag, for long flag, it always add long flag argument even if it doesn't match.So I rename from original
parse_internal_calltoparse_realcomp_internal_call, which is used for auto-completion, and nushell's custom command. For known extern, the main parsing logic is inparse_known_extern_callparse_internal_call_loosely.Then I make a copy of
parsefunction calledparse_for_completion, the different between them is just the way to parse custom command and known external. Inparse_for_completion, it will always go toparse_realcomp_internal_call. In normalparse, it may goes toparse_known_external_callparse_internal_call_looselyorparse_realcomp_internal_call, based onSignature.is_known_externalSignature.allows_unknown_flagsattribute.## One restriction for unknown flag Because it's unknown, we don't know if it's taking value or not, so some flags which take values will not likely work
Take the following extern as example:
We can't pass an unknown flag which takes values, which means the following doesn't work:
Tests + Formatting
Don't forget to add tests that cover your changes.
Make sure you've run and fixed any issues with these commands:
cargo fmt --all -- --checkto check standard code formatting (cargo fmt --allapplies these changes)cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collectto check that you're using the standard code stylecargo test --workspaceto check that all tests passAfter Submitting
If your PR had any user-facing changes, update the documentation after the PR is merged, if necessary. This will help us keep the docs up to date.