Skip to content

Commit

Permalink
Fix bug in compdump logic
Browse files Browse the repository at this point in the history
Compdump was erroneously regenerated on every startup.

Fixes #480
  • Loading branch information
marlonrichert committed Nov 16, 2022
1 parent f07efda commit 866c661
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions scripts/.autocomplete.compinit
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
#!/bin/zsh
zmodload -Fa zsh/files b:zf_rm
zmodload -F zsh/parameter p:funcstack p:functions
builtin autoload -RUz is-at-least

typeset -gHa _autocomplete__compdef=()
compdef() {
typeset -gHa _autocomplete__compdef=( $_autocomplete__compdef[@] "${(j: :)${(@q+)@}}" )
}

[[ -v functions[_bash_complete] ]] ||
_bash_complete compgen complete () {
unfunction _bash_complete compgen complete
builtin autoload +X -Uz bashcompinit
bashcompinit
bashcompinit() { : }
${(%):-%N} "$@"
}
_bash_complete compgen complete () {
unfunction _bash_complete compgen complete
builtin autoload +X -Uz bashcompinit
bashcompinit
bashcompinit() { : }
${(%):-%N} "$@"
}

.autocomplete.compinit.precmd() {
emulate -L zsh
Expand All @@ -33,19 +32,20 @@ compdef() {
typeset -gH \
_comp_dumpfile=${_comp_dumpfile:-${ZSH_COMPDUMP:-${XDG_CACHE_HOME:-$HOME/.cache}/zsh/compdump}}

if [[ -v _comps && $_comps[-command-] != _autocomplete.command ]]; then
if [[ -v _comps[-command-] && $_comps[-command-] != _autocomplete.command ]]; then

This comment has been minimized.

Copy link
@aninder

aninder Aug 3, 2024

the Compdump bug doesn't seem to have entirely been fixed as it's still getting called during every run with the latest codebase(as of today). The issue seems to on this line . If _comps[-command-] doesn't have a value then all is well. but if it has and in my case it is always _autocd then it removes the $_comp_dumpfile .
so what this comparison is intended to do anyway ? is _comps[-command-] set by _autocomplete.command and we want to make sure that this is the case , or something on that lines ?

zf_rm -f $_comp_dumpfile
else
local -Pa comps=( ~zsh-autocomplete/functions/completion/_autocomplete.*~*.zwc(N-.) )
local -Pa compfuncfiles=( ~zsh-autocomplete/functions/completion/_autocomplete.*~*.zwc(N-.) )

if ! (( $#comps )); then
print -u2 -- 'zsh-autocomplete: Failed to find completion functions. Aborting.'
if ! (( $#compfuncfiles )); then
print -u2 -- 'autocomplete: Failed to find completion function files. Aborting.'
return 66
fi

# Check if any of our function files are newer than the comp dump file.
local -P f=
for f in $comps[@]; do
if ! [[ -v functions[$f:t] && $f -ot $_comp_dumpfile ]]; then
for f in $compfuncfiles[@]; do
if [[ -v functions[$f:t] && $f -nt $_comp_dumpfile ]]; then
zf_rm -f $_comp_dumpfile
break
fi
Expand Down

2 comments on commit 866c661

@gilice
Copy link

@gilice gilice commented on 866c661 Dec 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion this would be worth a release because of the speedups. What do you think?

@marlonrichert
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gilice Sure. I'll try to make a new release soon, once I'm certain main is stable and production-ready.

Please sign in to comment.