mattmc3 / zephyr

:wind_face: A Zsh framework as nice as a cool summer breeze
MIT License
122 stars 13 forks source link

Completion files from local paths are not picked up #22

Closed amitds1997 closed 2 months ago

amitds1997 commented 6 months ago

Local completion files are not loaded after compinit. I tried to load completion for poetry by putting it in a completion directory but that did not work.

The steps to reproduce below walk through poetry completion but I think it should work for any local ZSH completion script.

System information

zsh --version # zsh 5.9 (x86_64-pc-linux-gnu)
antidote --version # antidote version 1.9.6 (3a30f36)
uname -a # Linux archlinux 6.7.9-arch1-1 #1 SMP PREEMPT_DYNAMIC Fri, 08 Mar 2024 01:59:01 +0000 x86_64 GNU/Linux

Steps to reproduce

  1. Create following files in any directory (later referred as <path-to-zshrc-dir>).
.zshrc ```zsh # Where to put antidote files? ANTIDOTE_HOME=$ZDOTDIR/plugins/.external # Get antidote if not already present [[ -e $ZDOTDIR/.antidote ]] || git clone --depth=1 https://github.com/mattmc3/antidote.git $ZDOTDIR/.antidote # Set the name of the static .zsh plugins file antidote will generate. ZSH_PLUGINS_FILE=${ZDOTDIR:-~}/.zplugins.zsh # Ensure you have a .zplugins.txt file where you can add plugins. [[ -f ${ZSH_PLUGINS_FILE:r}.txt ]] || touch ${ZSH_PLUGINS_FILE:r}.txt # Lazy-load antidote. fpath+=(${ZDOTDIR:-~}/.antidote/functions) autoload -Uz $fpath[-1]/antidote # Install all plugins there are if not already done [[ -e $ZDOTDIR/plugins/.external ]] || antidote load $ZDOTDIR/.zplugins.txt # Generate static file in a subshell when .zsh_plugins.txt is updated. if [[ ! $ZSH_PLUGINS_FILE -nt ${ZSH_PLUGINS_FILE:r}.txt ]] || [[ ! -s $ZSH_PLUGINS_FILE ]]; then source $ZDOTDIR/.antidote/antidote.zsh (envsubst < ${ZSH_PLUGINS_FILE:r}.txt | antidote bundle >| $ZSH_PLUGINS_FILE) fi # Source your static plugins file. source $ZSH_PLUGINS_FILE # vim: ft=zsh sw=2 ts=2 et ```
.zplugins.txt ```zsh $ZDOTDIR/completions kind:fpath # belak/zsh-utils path:completion mattmc3/zephyr path:plugins/completion # vim: ft=zsh sw=2 ts=2 et ```
  1. Install poetry and install it's completion script to <path-to-zshrc-dir>/completions/_poetry using poetry completions zsh > <path-to-zshrc-dir>/completions/_poetry. (docs). This can be replaced with any completion, but this is the one I am trying to get to work.
  2. Run ZDOTDIR=<path-to-zshrc-dir> zsh.
  3. In the launched shell, running poetry <TAB> should show completions but it does not.

What works?

Thanks for your amazing work on this and for sharing your dotfiles. They helped me a lot to get my zsh in order :heart:

l-lin commented 2 months ago

TLDR: Delete $HOME/.cache/zsh/zcompdump, open a new terminal and your custom completion should be present.


When you execute compinit, there's a zcompdump that is created: https://zsh.sourceforge.io/Doc/Release/Completion-System.html#Completion-System

To speed up the running of compinit, it can be made to produce a dumped configuration that will be read in on future invocations; this is the default, but can be turned off by calling compinit with the option -D. The dumped file is .zcompdump in the same directory as the startup files (i.e. $ZDOTDIR or $HOME); alternatively, an explicit file name can be given by ‘compinit -d dumpfile’. The next invocation of compinit will read the dumped file instead of performing a full initialization.

You can see this file as some sort of cache.

Zephyr is using this file in a smarter way: https://github.com/mattmc3/zephyr/blob/81193c9683c6a212efbcc4c07b62c9e62317fc93/plugins/completion/functions/run-compinit#L16-L33

The "cache" is 20 hours long, so unless you delete it yourself, your configuration will not have your new completion file.

Or, if you replace zephyr completions with zsh-utils' completion plugin, it works.

Zephyr is looking for zcompdump at $HOME/.cache/zsh/zcompdump: https://github.com/mattmc3/zephyr/blob/81193c9683c6a212efbcc4c07b62c9e62317fc93/plugins/completion/functions/run-compinit#L16

whereas zsh-utils looks at either $HOME/.cache/zsh/compdump or $HOME/.zcompdump or $HOME/.config/zsh/.zcompdump depending on your config: https://github.com/belak/zsh-utils/blob/0e3238b6462fd5cd7c4c6b5d1dccbe5a69d2b5b4/completion/completion.plugin.zsh#L14-L18

So my guess is that when you switched to zsh-utils, you created a new cache and could use your poetry completion.

amitds1997 commented 2 months ago

Thanks, I'll have a look later on. Closing this since this is no longer an issue for me (and seems like something at my end rather than a bug).