marlonrichert / zsh-autocomplete

πŸ€– Real-time type-ahead completion for Zsh. Asynchronous find-as-you-type autocompletion.
MIT License
5.17k stars 142 forks source link

Freezes for a few seconds on entering a command #736

Open Mosazghi opened 1 month ago

Mosazghi commented 1 month ago

Environment

% typeset -p1 VENDOR OSTYPE ZSH_PATCHLEVEL _autocomplete__funcfiletrace
<output>
typeset VENDOR=ubuntu
typeset OSTYPE=linux-gnu
typeset ZSH_PATCHLEVEL=ubuntu/5.9-6ubuntu2
typeset -a _autocomplete__funcfiletrace=(
  /home/mosa/.oh-my-zsh/custom/plugins/zsh-autocomplete/zsh-autocomplete.plugin.zsh:4
  /home/mosa/.oh-my-zsh/oh-my-zsh.sh:175
  /home/mosa/.oh-my-zsh/oh-my-zsh.sh:204
  /home/mosa/.zshrc:27
  zsh:0
)
<output>

config file

 export ZSH="$HOME/.oh-my-zsh"

 ZSH_THEME="amuse"

 source $ZSH/oh-my-zsh.sh

 # Path to your oh-my-zsh installation.
 export ZSH="$HOME/.oh-my-zsh"
 export PATH="/usr/local/MATLAB/R2023b/bin:$PATH"
 export DOTNET_ROOT=$HOME/.dotnet
 export PATH=$PATH:$DOTNET_ROOT:$DOTNET_ROOT/tools
 export PATH="$PATH:/opt/nvim-linux64/bin"
 export VCPKG_ROOT="$HOME/vcpkg"
 export PATH=$VCPKG_ROOT:$PATH

 zstyle ':omz:update' frequency 13

 ENABLE_CORRECTION="true"

  DISABLE_UNTRACKED_FILES_DIRTY="true"

 HIST_STAMPS="mm/dd/yyyy"

plugins=(git themes zsh-autosuggestions zsh-syntax-highlighting fast-syntax-highlighting zsh-autocomplete)
source $ZSH/oh-my-zsh.sh
#
# # User configuration

  export MANPATH="/usr/local/man:$MANPATH"

  _dotnet_zsh_complete()
  {
    local completions=("$(dotnet complete "$words")")

    # If the completion list is empty, just continue with filename selection
    if [ -z "$completions" ]
    then
      _arguments '*::arguments: _normal'
      return
    fi

    # This is not a variable assignment, don't remove spaces!
    _values = "${(ps:\n:)completions}"
  }

  compdef _dotnet_zsh_complete dotnet
  #source "$HOME/.cargo/env"
  . "$HOME/.cargo/env"   
  export PATH="$PATH:/home/mosa/.local/bin"

  export NVM_DIR="$HOME/.nvm"
  [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
  [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
  export HISTFILESIZE=10000000
  export HISTSIZE=10000000
  export HISTFILE=~/.zsh_history

  setopt HIST_FIND_NO_DUPS
  # following should be turned off, if sharing history via setopt SHARE_HISTORY
  setopt INC_APPEND_HISTORY

zstyle ':completion:*' list-prompt   ''
zstyle ':completion:*' select-prompt ''
  zstyle ':fzf-tab:complete:cd:*' fzf-preview "ls --color $realpath"
  fpath+=${ZDOTDIR:-~}/.zsh_functions
  export BAT_THEME=gruvbox-dark
  export QT_QPA_PLATFORM=xcb
  export IDF_PATH=~/esp/esp-idf
  export PATH=~/esp/xtensa-esp32-elf/bin:$PATH
  export PATH=/path/to/mxe/usr/bin:$PATH
  [ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
 #
 #
  # Aliases 
  alias zshconfig="mate ~/.zshrc"
  alias ohmyzsh="mate ~/.oh-my-zsh"
  alias n="nvim"
  # alias ls="ls --color"
  alias cat="batcat"
  alias kittyupdate="curl -L https://sw.kovidgoyal.net/kitty/installer.sh | sh /dev/stdin"
  alias get_idf='. $HOME/esp/esp-idf/export.sh'
  alias idf="idf.py"
  alias lg="lazygit"
  alias idfb="idf build -DCMAKE_EXPORT_COMPILE_COMMANDS=1"
  alias idff="idf flash"
  alias idfr="idfb && idff"
  alias idfrm="idfr && idf monitor"
  alias lg="lazygit"
  alias mr="mosquitto -v -c /etc/mosquitto/conf.conf"

Steps to reproduce

So when typing commands like sudo apt update <space> git clone <space> sudo apt upgrade <space> It freezes for a few seconds. But it gets annoying so i just CTRL + C and this is the output. image

% cd $(mktemp -d)
% git clone --depth 1 -- https://github.com/marlonrichert/zsh-autocomplete.git
<output>
% > .zshrc <<EOF
setopt interactivecomments transientrprompt
PS1='%# '
PS2=
RPS2='%^'
source $PWD/zsh-autocomplete/zsh-autocomplete.plugin.zsh
EOF
% env -i HOME=$PWD PATH=$PATH TERM=$TERM ${TERMINFO:+TERMINFO=$TERMINFO} zsh -d
% <inputs>
<output>

^ Do the above. I notice the freezes only last about 1 second now, but still noticeable.

Contents of ~autocomplete-log/YYYY-MM-DD.log (click to expand)
$ cat 2024-07-01.log 
───────┬──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       β”‚ File: 2024-07-01.log
───────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   β”‚ .autocomplete:async:pty:zle-widget:15: completion cannot be used recursively (yet)
   2   β”‚ .autocomplete:async:complete:fd-widget:35: completion cannot be used recursively (yet)
   3   β”‚ .autocomplete:async:complete:fd-widget:35: completion cannot be used recursively (yet)
S-Yuan137 commented 1 month ago

I have similar things when I use rsync and tab to complete the folder names.

jo3-l commented 1 month ago

I bisected the issue locally to https://github.com/marlonrichert/zsh-autocomplete/commit/bbbefed0f27502917b0812a02cd38f32aab55770, which seems a plausible cause as the commit adjusts the main completion logic. At the previous commit, https://github.com/marlonrichert/zsh-autocomplete/commit/adfade31a84dfa512a7e3583d567ee19ac4a7936, completion works as expected without any freezing for me. So a potential workaround for this bug is to git checkout adfade3 in one's installation of zsh-autocomplete.

Unfortunately, I am not familiar enough with shell or zsh plugins to suggest a fix, but hopefully this helps with investigation.