feat: external completions for commands/flags#6295
Conversation
| _ => {} | ||
| } | ||
| } | ||
| Err(err) => println!("failed to eval completer block: {}", err), |
There was a problem hiding this comment.
What should we do if we fail to eval the block?
There was a problem hiding this comment.
I'm of the idea that it should return a Result, but that will change more things in the code
There was a problem hiding this comment.
Yeah, but then it goes back to the fn completion_helper(...) -> Vec<Suggestion> { which should handle it anyway and return a Vec<Suggestion>
|
Would also be nice to move the |
| _ => {} | ||
| } | ||
| } | ||
| Err(err) => println!("failed to eval completer block: {}", err), |
There was a problem hiding this comment.
I'm of the idea that it should return a Result, but that will change more things in the code
c413b85 to
b9f35fb
Compare
|
I found these issues testing this PR:
In both cases, the external completer should be triggered after trying Nushell's completions, not before, because it prevents us from completing built-in commands and flags correctly. But in principle, these two cases seems like the right places where to trigger the external completer. It just needs to be moved lower in priority. |
|
@kubouch what do you mean by moving them lower in priority? We need to check if nushell internals return empty, if so we trigger the external, is that what you mean? |
Yeah, that's what I mean. Check if Nushell completions return something and if not, try the external completer. |
Got it, I will update the PR then |
|
There also seems to be a fundamental step missing compared to how nushell passes arguments to a command. Here gh issue list --label 'good first issue',<TAB>
# ''good first issue',0.67' Issues that should be fixed in v0.67
# ''good first issue',Stale' used for marking issues and prs as staleMore apparent with the string interpolation which results in slices kinda like this: ls $"($env.HOME)"<TAB>
# [ 'ls', '$"', '(', '$env', 'HOME', ')', '"a' ] |
|
@rsteube The eval step for the argument is a good idea, but I would leave it for a future work. I'd rather get this PR merged first for simple cases. About the quotes, |
I think the error here might be related to the long-standing bug that if there is an empty input, it defaults to completing all the commands. Like when you press You want to complete commands only in two cases:
Also, it seems to me, the file completion should have a priority over command completion. Currently, it first tries commands, then files but I'm wondering if it should be the other way. So, to sum up, it seems the error here is in the completion logic itself, not in introducing the external completer. What we could do is to land this PR and make a new PR to fix the other completion issues. However, we should probably make some list to document the cases where we know the completions are broken. There is also #6257 which might be about fixing the same command completion issue. It introduces a new syntax shape, though, which we thought might not be the best approach. You might want to take a look at it and maybe work together with @merelymyself if you want to address the wrong command completions. |
|
How can we have a minimum working version so the users can test and give some feedback. Maybe we can address some corner cases later given user's feedback? |
|
Yes, the |
|
Yeah @kubouch I think that test failing is related to the issue we discussed. Should I remove that test then? I can give priority to external completer for commands for now, then once we fix the issue discussed before we give priority to Nu again, what do you think? |
|
OK, if it's related to the I think if you prioritize the external completer, it would call to it before completing the Nushell command which is not what we want. I suspect prioritizing the external completer would need a bit of extra logic I outlined earlier to make it work reliably. Like And one more thing: Because you added a new config option, could you please put an example entry to the default config (commented out or set to |
|
OK, let's give this a try! Thanks for the effort! |
|
@herlon214 The merged version doesn't work for me ( |
* wip * wip * cleanup * error message * cleanup * cleanup * fix clippy * add test * fix span * cleanup * cleanup * cleanup * fixed completion * push char * wip * small fixes * fix remove last span * fmt * cleanup * fixes + more tests * fix test * only complete for commands * also complete flags * change decl_id to block_id * use nu completion first * fix test * ignore test * update config section

Description
This PR adds support to use external completions (like carapace) instead of Nushell completions by adding a new config called
external_completerwhich is optional.Basically, if you set one
external_completerit will use it instead of our current Nushell completion flow for commands and flags.Current issues:
git config --<tab>)aadded in the spanschown "<TAB>) <--- We will leave this one up to theexternal_completerNu function handleTests
Make sure you've done the following:
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 --features=extra -- -D warnings -D clippy::unwrap_used -A clippy::needless_collectto check that you're using the standard code stylecargo test --workspace --features=extrato check that all the tests pass