Fix zsh completion showing all PATH entries for +toolchain arg#4763
Conversation
|
@simonhkswan Thanks for investigating! Do you think your fix will address #2268 / #4532 as well, or at least a part of them? The symptoms look pretty similar... |
The optional +toolchain positional argument was defined without a value_hint, causing clap_complete to generate zsh completions with the `_default` action. In zsh, `_default` suggests all executables on $PATH, polluting the completion menu with thousands of irrelevant entries alongside the actual rustup subcommands. Adding `value_hint = ValueHint::Other` prevents clap_complete from emitting `_default`, so only the intended subcommand completions appear.
5c4dfe4 to
e378f84
Compare
So I believe this PR directly addresses problem 1 from #2268 — Problem 2 from #2268 ( #4532 seems closed as a duplicate but maybe the same approach mentioned above could address this too. |
|
@simonhkswan Sounds good! Did you test this change on your machine? If it works well I'd love to merge it and update the problem description to leave the second problem above for further discussion. |
@rami3l - I did test it (and actually using it permanently now :) |
|
@simonhkswan Cool, and thanks again for your contribution! |

Problem
When using zsh completions generated by
rustup completions zsh, typingrustup <TAB>shows every executable on$PATHalongside the actual rustup subcommands (install,update,show, etc.). This makes the completion menu nearly unusable — thousands of irrelevant entries mixed in with the ~15 real subcommand completions.How to reproduce
rustup completions zsh > _rustup_rustupon your$fpathand reload the shell (exec zsh)rustupand press<TAB>$PATHappear in the completion listCause
The
+toolchainoptional positional argument insrc/cli/rustup_mode.rsis defined without avalue_hint. Whenclap_completegenerates zsh completions, arguments with no hint default toValueHint::Unknown, which the zsh generator maps to the_defaultcompletion action (source):This produces the following in the generated completion script:
In zsh,
_defaultis a catch-all completer that suggests files and commands on$PATH. Since this is an optional positional argument (::prefix), zsh offers these completions alongside the subcommand completions every time.Fix
This PR adds
value_hint = ValueHint::Otherto the+toolchainargument. In the zsh generator,ValueHint::Othermaps to an empty string — no completion action — which prevents the PATH pollution. Rustup subcommand completions continue to work as expected.Future improvement
A more complete solution would be to provide dynamic completions for the
+toolchainargument usingclap_complete'sArgValueCompleter, which could callrustup toolchain listat completion time to suggest installed toolchains. That would be a larger change involving adoption ofclap_complete's dynamic completion infrastructure, so this PR focuses on the minimal fix to eliminate the broken behavior.