Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Completions Provided by Plugins Not Working #698

Open
l04m33 opened this issue Jan 16, 2020 · 4 comments
Open

Completions Provided by Plugins Not Working #698

l04m33 opened this issue Jan 16, 2020 · 4 comments

Comments

@l04m33
Copy link

l04m33 commented Jan 16, 2020

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

  • antigen version: v2.2.2 (8846aa9)
  • zsh --version: zsh 5.7.1 (x86_64-redhat-linux-gnu)

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
Copy link

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

compdef () {}
). Why is that?

Related issue: ohmyzsh/ohmyzsh#9139.

@alxdrl
Copy link

alxdrl commented Aug 18, 2021

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
Copy link

Sarke commented Jan 9, 2022

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:
#701
#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 #698 (comment), which seems to be the heart of the matter.

@Sarke
Copy link

Sarke commented Jan 9, 2022

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

compdef () {}

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

It seems this is the reason: "Defer bundle loading to antigen-apply command" #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 () {}

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

No branches or pull requests

4 participants