New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
extern
definitions that map to aliases can't be executed
#4618
Comments
I think we need to add aliases to the Another piece is that both For the cases you show where it's failing to run the executable, I'd like to see if we can dig into why. Aliases shouldn't have any particular restrictions here, but perhaps they aren't playing well with subcommands? |
So in my testing - The only thing that makes the alias break is the definition of For example:
|
extern
definitions that map to aliases can't be executed
For folks who want to look into this one - I think this is coming from a hack that we're doing for Right now, in order to retain this original order, we re-parse the expression as an external command. For simple forms, this is fine. For forms like the above, where we need to expand an alias to get to the original, it's not going to work. There are probably a few ways to fix this. My hunch is that we may want to parse it both as an internal command, so that we can do typechecking and completions, and as an external command (both using alias expansion). In the future, perhaps we'll have a way to denote in the signature that the command needs to retain its original order. |
@lukexor unrelated to this issue, these are really cool custom completions. we should put them in the nu_scripts repo somewhere like under engine-q/completions or something. |
I just also ran into this bug, but it seems you can work around it by prepending the external command with |
Any update on design ideas here? I really want to make use of the completion support, but there's no way I can type the full commands in my day to day for it. Though I just had a thought that I could work around it by just defining the completions on my aliases instead, albeit there may be some duplication. Edit: Tried the above, but I don't think it's possible. |
The completion works, but actual execution fails so tab-completion seems to know the alias is associated to the extern command, but the execution parser isn't.
|
I'm trying to look into this myself to give more insight - so far the most I've been able to gather is that potentially there is a span mismatch going on. The
Here the The
The same |
So I found that if I comment out this line in parser.rs, it works as expected:
Though I'm not clear on what impact this has or why you'd want to replace an alias expansion span with the original pre-expanded span. If someone can advise - I'll be happy to put up a PR Related: #4474 Note I went through and tried the steps in JT's screenshots and they seem to work fine without replacing the spans. All tests also pass, but #4473 is still an issue |
I might be missing something, but it seems like spans are doing double duty - as both an execution reference for declaration blocks as well as for error messaging - which would definitely get tricky with alias expansion being involved. I'd expect having I tried looking into a different way to solve #4474 - The output I keep getting is that additional expressions are being added to the pipeline that are outside of the range of the initial expansion.
The expression expansion parsing shows "start" followed by an "a" string expression - The span for which is outside of the range of the expansion span. By replacing the expansion span with the original, this "a" never shows up in the arguments for expression parsing. e.g.
vs.
|
This and #5179 seem to be related. @lukexor, as you rightly point out, line 979, where we replace the span is problematic. For external commands, we rely on getting the span contents to know which command to run. By replacing the new span with the original, we end up passing the alias to It gets a bit trickier with subcommands. In the issue I linked, the user is trying to alias It seems to me that a hacky solution would be to try to expand aliases again in I suspect the way we expand aliases is also related to the unhelpful error messages (#4965). |
@filaretov it does! Thanks so much - I can't believe how simple the fix was! |
@lukexor Yeah, I was pleasantly surprised as well 😁 |
Describe the bug
I am loving the new way to provide custom completion sources - but I'm having trouble getting it to work when aliases overlap with the external command.
I have a
alias cre = cargo run --example
- the completion works fine, but it will only execute if you type out the full command (e.g.cargo run --example 2d_raycasting
)How to reproduce
cre <Tab>
in a cargo project with anexamples/
folder<Enter>
<Enter>
again to execute the commandExpected behavior
Expected that
cargo run --example <auto-completed-example>
is executedInstead:
Note that running
cargo run --example 2d_raycasting
works as expected and reproduce the above steps above by starting out typingcargo run --example <Tab>
works as expected.Screenshots
No response
Configuration
Additional context
This also doesn't work for normal commands either (not involving flags). Using the default config
get checkout
completion with an alias ofalias gco = git checkout
results in a similar failure:The text was updated successfully, but these errors were encountered: