fix(cli): zsh completion completes on first TAB when installed to fpath#293
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #292. After that landed,
gradient <TAB>completed under bash and fish but not zsh.Root cause: clap_complete's dynamic zsh script is built to be sourced, where it registers
_clap_dynamic_completer_gradientimmediately. The Nix package (installShellCompletion --zsh) instead installs it as an fpath autoload#compdeffile. There, zsh registers the file itself (_comps[gradient]=_gradient) and the script only re-registers the real completer viacompdefon the first TAB — so the first TAB produces nothing and only the second works. bash/fish are sourced at shell init, so they were unaffected.Fix:
gradient completion zshnow appends an autoload bridge that runs the completer on the file's first invocation, while staying inert when the script is sourced:Verified end-to-end with a real zsh +
zpty: the fpath-autoloaded file now completesgradient ca<TAB>->cacheon the first TAB, and the sourced form still registers_clap_dynamic_completer_gradientwithout firing the bridge at source time.Test plan
cli/tests/completion.rs::completion_zsh_bridges_autoload_first_tabasserts the appended bridge line is present.cargo clippy --manifest-path cli/Cargo.toml --all-targetspasses clean.gradient completion zsh > $fpath_dir/_gradient, new shell,gradient ca<TAB>completes on first press.