-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
WIP: Add cargo completions
command for shell completions.
#9288
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
Thanks for your interest in moving this forward! This isn't quite the direction that I was thinking for #6645. There are some details written in that issue, but in general the idea is that the completion file would delegate all the work to cargo itself. This would likely be a large amount of work, but I think it would be worth it for improved completion support. |
Right. Either way, I think the only approach that makes sense is to auto-generate the completions from clap, because otherwise you add maintenance to every command to make sure that completions stay up to date with new options and stuff. There's some use-cases that can't be covered with a static list of completions (eg On the long term I think using clap's dynamic completions once they're implemented is the most efficient solution. |
☔ The latest upstream changes (presumably #9292) made this pull request unmergeable. Please resolve the merge conflicts. |
Sorry, I'm not sure I understand why it would "add maintenance to every command". Can you explain that more? I would not expect there to be any required effort for new commands, unless they want to add more intelligent completion beyond the information clap has. |
Isn't that already happening? They call the On a side note, is there a reason why the name is |
cargo complete
command for shell completions.cargo completions
command for shell completions.
You're right, that was an oversight on my part.
Can you clarify what you mean? Calling
Okay, so, there are two ways to do completions:
Right now, the first approach can be auto-generated by clap, which this PR does. You call The second approach doesn't have clap support yet. That means, if you want to go for this approach, you have to add your own metadata to each command (or use clap's metadata somehow, maybe). You need a way for your I've asked around and a clap maintainer says that implementing an auto-complete feature is on the roadmap, but requires internal refactorings. In the meantime, this is the most efficient solution available. |
That's what I meant. Your PR already did this. I wasn't aware that the person above was talking about the second approach you just described, the auto suggestion system. Honestly, I think that the current solution is good enough. It's better than nothing, basically introduces no code that needs active maintenance and provides solid completions. |
My intent was to use the metadata from clap itself so there wouldn't need to be anything additional added. There are some private APIs in clap for fetching the information, which I would consider using. I wouldn't want to proceed with this approach because it is a regression from the current completion support, which has intelligent completions for various options. |
What do you mean? |
The existing completions are able to complete values for some options (particularly the bash completions, which are more complete). Some examples:
Ideally, built-in completions would improve on the current completions to make these completions more reliable and accurate. |
What do you mean, the "existing completions"? As far as I'm aware, the only completions are the ones written by the respective shell maintainers (eg bash, fish, etc). At the very least I'm the one who updated the fish completions and they were very much incomplete. EDIT - And just to be clear, it's completely possible to use a mix of auto-generated and manual commands for these completion files that do the smart completions you mention. |
The completions here, which are included in the distribution in the |
Okay, I'm going to be blunt here: I feel like you're arguing against my PR because it doesn't match the vision you had, and not considering the PR on its merits. If pushing this PR means I have to fight with you to defend it, I'm not going to bother. If you think you have a better idea to achieve the same thing, go ahead and implement it. As for the file you linked:
|
I'm going to close this, as I don't think this is the direction we want to go. A hybrid approach is certainly an option, and if there is interest in pursuing that, I think it can be considered. However, before doing that I would ask for the following:
|
Solves #6645
Should help with #9086. Might help with #8871, #7864, and #5759 if dynamic completion support is added to clap.
The "WIP" part is because this is my first cargo PR and I don't know the conventions. In particular, I don't know how errors should be handled, so the PR has a big nasty
.expect
right in the middle.Also, I'm using the imperative syntax because it's what existing code does, but I feel like I should be using
#[derive(Clap)]
instead? I dunno.TODO