Skip to content

fix(cli): zsh completion completes on first TAB when installed to fpath#293

Merged
DerDennisOP merged 1 commit into
mainfrom
fix/cli-zsh-completion-autoload
May 29, 2026
Merged

fix(cli): zsh completion completes on first TAB when installed to fpath#293
DerDennisOP merged 1 commit into
mainfrom
fix/cli-zsh-completion-autoload

Conversation

@DerDennisOP
Copy link
Copy Markdown
Member

@DerDennisOP DerDennisOP commented May 29, 2026

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_gradient immediately. The Nix package (installShellCompletion --zsh) instead installs it as an fpath autoload #compdef file. There, zsh registers the file itself (_comps[gradient]=_gradient) and the script only re-registers the real completer via compdef on 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 zsh now appends an autoload bridge that runs the completer on the file's first invocation, while staying inert when the script is sourced:

[[ ${funcstack[1]} = _gradient ]] && _clap_dynamic_completer_gradient "$@"

Verified end-to-end with a real zsh + zpty: the fpath-autoloaded file now completes gradient ca<TAB> -> cache on the first TAB, and the sourced form still registers _clap_dynamic_completer_gradient without firing the bridge at source time.

Test plan

  • cli/tests/completion.rs::completion_zsh_bridges_autoload_first_tab asserts the appended bridge line is present.
  • cargo clippy --manifest-path cli/Cargo.toml --all-targets passes clean.
  • Manual: gradient completion zsh > $fpath_dir/_gradient, new shell, gradient ca<TAB> completes on first press.

@DerDennisOP DerDennisOP merged commit 73a266a into main May 29, 2026
7 checks passed
@DerDennisOP DerDennisOP deleted the fix/cli-zsh-completion-autoload branch May 29, 2026 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant