kislyuk / argcomplete

Python and tab completion, better together.
https://kislyuk.github.io/argcomplete/
Apache License 2.0
1.39k stars 129 forks source link

Fix zsh global install #466

Closed evanunderscore closed 6 months ago

evanunderscore commented 6 months ago

This fixes zsh global completion breakage introduced in #463, and updates the test to use a similar method as activate-global-python-argcomplete for zsh.

The zsh global completion script was previously mixing paradigms; it seems that you are supposed to use a file with a #compdef comment which is autoloaded, or manually call compdef yourself. I've updated this to only use the #compdef comment, but it does feel like everything would be simpler if we went the other way and sourced the file directly as we do with bash. The only catch with that is we would probably have to append this to ~/.zshrc instead of ~/.zshenv since we need compdef to be available, and it seems undesirable to autoload compdef on the user's behalf.

codecov-commenter commented 6 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (d696194) 81.12% compared to head (6095cde) 81.12%. Report is 1 commits behind head on develop.

:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## develop #466 +/- ## ======================================== Coverage 81.12% 81.12% ======================================== Files 10 10 Lines 784 784 ======================================== Hits 636 636 Misses 148 148 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

kislyuk commented 6 months ago

@evanunderscore as far as I know, we can't source the file directly (at least not without making our installation process a lot less general). Zsh has no default facility to source completion scripts at startup - instead it scans the first lines of these files for compdef declarations. The actual scripts are sourced on demand according to those declarations.

By the way, we will be facing something similar with bash soon. Bash completion v1 (which is what we use for global completion installation) sources entire scripts, but it's deprecated. Bash completion v2 uses a similar lazy-load pattern that does not allow registering a global completion fallback (complete -D, which is what we use).

We could always use the alternative strategy of telling the user to source the file directly in their rc script, but that's not a systemwide installation method and it's brittle in other ways.

Testing this branch now.

kislyuk commented 6 months ago

Testing looks good, I agree this approach seems to be the best.

kislyuk commented 6 months ago

Released in v3.2.0.