zsh-users / antigen

The plugin manager for zsh.
http://antigen.sharats.me
MIT License
8k stars 279 forks source link

Completions Provided by Plugins Not Working #698

Open l04m33 opened 4 years ago

l04m33 commented 4 years ago

Description

compdef in plugin scripts have no effect.

Steps to reproduce

Minimal .zshrc:

if [ ! -d "$HOME/.antigen" ]; then 
    git clone --branch master https://github.com/zsh-users/antigen.git "$HOME/.antigen"
fi
source $HOME/.antigen/antigen.zsh
antigen bundle fanzeyi/zsh-at
antigen apply

The zsh-at plugin provides an @ command, which provided its own completion function, but when I hit tab after the @ command, I got default filename completions.

Expected behavior:

- The `_zsh_at_completion` function provided by the plugin should be used for completions for the `@` command.

Software version

More information

By inspecting the cached script init.zsh, I found that:

  1. The compinit function was called in _antigen_compinit, which was called by a precmd hook;
  2. This precmd hook got triggered only after the init script was sourced, and before the first command prompt;
  3. All the plugin scripts sourced in the init script called an empty compdef function defined in the init script, with the zsh completion system uninitialized.
  4. When I got to a command prompt, no completion provided by plugins worked at all.

I found the code regarding completions quite confusing. Why not call _antigen_compinit directly instead of using a hook? Why is there an empty compdef function?

mcornella commented 4 years ago

I found the same, the compdef function is a no-op in the cache file (see https://github.com/zsh-users/antigen/blob/8846aa902047992e86816cbd941acc86646bd83b/src/ext/cache.zsh#L59). Why is that?

Related issue: https://github.com/ohmyzsh/ohmyzsh/issues/9139.

alxdrl commented 3 years ago

I'm having issue with the gcloud plugin completion not working

I've added a complete -p at the end of .zshrc that yields

    * Zsh will start quickly but prompt will jump down after initialization.

For details, see:
https://github.com/romkatv/powerlevel10k/blob/master/README.md#instant-prompt

-- console output produced during zsh initialization follows --

complete -o default -F _bq_completer bq
complete -o nospace -F _python_argcomplete gsutil
complete -o nospace -o default -F _python_argcomplete gcloud
complete _bash bash

Then at the prompt, doing a complete -p as the first command:

$ complete -p
complete _bash bash
$

When sourcing the completion script at the prompt and issuing complete -p once more I then get

$ source google-cloud-sdk/completion.zsh.inc
$ complete -p
complete -o default -F _bq_completer bq
complete -o nospace -F _python_argcomplete gsutil
complete -o nospace -o default -F _python_argcomplete gcloud
complete _bash bash
$

And completion is working from then on.

Somehow, the complete config vanishes while processing the first prompt...

Any idea ?

Greetings,

Sarke commented 2 years ago

I have this issue to, and so do many others. I think it keeps coming up because it's so hard to narrow down what the issue is.

Related: https://github.com/zsh-users/antigen/issues/701 https://github.com/zsh-users/antigen/issues/583

Also, this user might have found something releveant: https://unix.stackexchange.com/questions/670676/zsh-autocompletion-for-function-based-on-git-why-is-compdef-not-working-in-zsh/670942

When I type type compdef in my zsh, it says compdef is a shell function from /usr/share/zsh/functions/Completion/compinit, whereas when I include it in my .zshrc it prints compdef is a shell function from /home/dario/.antigen/init.zsh.

That is related to what @mcornella mentioned above https://github.com/zsh-users/antigen/issues/698#issuecomment-666681300, which seems to be the heart of the matter.

Sarke commented 2 years ago

I found the same, the compdef function is a no-op in the cache file (see

https://github.com/zsh-users/antigen/blob/8846aa902047992e86816cbd941acc86646bd83b/src/ext/cache.zsh#L59

). Why is that? Related issue: ohmyzsh/ohmyzsh#9139.

It seems this is the reason: "Defer bundle loading to antigen-apply command" https://github.com/zsh-users/antigen/pull/513

Commenting out these two lines in antigen makes the oh-my-zsh completions work again:

autoload -Uz add-zsh-hook; add-zsh-hook precmd _antigen_compinit
compdef () {}