Closed rayjanoka closed 2 years ago
cd $(mktemp -d)
git clone --depth 1 -- https://github.com/marlonrichert/zsh-autocomplete.git
> .zshrc <<EOF
PS1='%# ' PS2= RPS2='%^'; setopt transientrprompt interactivecomments
source ~/zsh-autocomplete/zsh-autocomplete.plugin.zsh
EOF
env -i HOME=$PWD PATH=$PATH TERM=$TERM ${TERMINFO:+TERMINFO=$TERMINFO} /bin/zsh-5.9 -d
% ferium modpack add
> identifier -- The identifier of the modpack/project
> The Modrinth project ID is specified at the bottom of the left sidebar under 'Technical information'. You can also use the > > project slug for this
> The CurseForge mod ID is specified at the top of the right sidebar under 'About Project'
% ferium modpack
There will be no suggestions for the last command(> is for its suggestions)
pc linux-gnu /bin/zsh /bin/zsh zsh-5.9-0-g73d3173
/home/kyle/.local/share/zinit/zinit.git/zinit.zsh:1633
/home/kyle/.local/share/zinit/zinit.git/zinit.zsh:1271
/home/kyle/.local/share/zinit/zinit.git/zinit.zsh:2688
/home/kyle/.zshrc:51
5b0073d (HEAD -> main, origin/main, origin/HEAD) Check that `$ZSH_COMPDUMP` file can be read
But after downgrading to zsh 5.8.1
everything went back to normal
I'm unable to reproduce this:
% cd $(mktemp -d)
% git clone --depth 1 -- https://github.com/marlonrichert/zsh-autocomplete.git
Cloning into 'zsh-autocomplete'...
remote: Enumerating objects: 59, done.
remote: Counting objects: 100% (59/59), done.
remote: Compressing objects: 100% (55/55), done.
remote: Total 59 (delta 0), reused 27 (delta 0), pack-reused 0
Receiving objects: 100% (59/59), 1.64 MiB | 1.21 MiB/s, done.
% > .zshrc <<EOF
PS1='%# ' PS2= RPS2='%^'; setopt transientrprompt interactivecomments
source ~/zsh-autocomplete/zsh-autocomplete.plugin.zsh
EOF
% env -i HOME=$PWD PATH=$PATH TERM=$TERM ${TERMINFO:+TERMINFO=$TERMINFO} /usr/local/opt/zsh/bin/zsh -d
% print $ZSH_VERSION
5.9
% cd zsh-autocomplete
% cd ..
% cd zsh-autocomplete
% cd ..
% cd zsh-autocomplete
% cd ..
% cd zsh-autocomplete
% cd ..
% cd zsh-autocomplete
% cd ..
% cd zsh-autocomplete
% cd ..
% cd zsh-autocomplete
% cd ..
% cd zsh-autocomplete
% cd ..
% cd zsh-autocomplete
% cd ..
% cd zsh-autocomplete
% cd ..
% cd zsh-autocomplete
% cd
directory
functions/ scripts/
But I can! The number of cd
steps when this problem occurs is not a static value
Ex.
I did it in 3 steps, but other times, I did it in 15 steps instead. I think the way to consistant produce it is to actually type out every letter instead of doing up
and selecting it.
yes not exactly static, go slowly, using the up arrow doesn't work. I'm on an M1 cpu.
cd z\
Can verify this breaks the completions for me as well. manjaro + zsh 5.9
Same here. After pressing the Enter key exactly 27 times, every time, the completions disappear. The problem occurs only on zsh 5.9, downgrading to 5.8.1 fixes it.
Same here (manjaro + Konsole + zsh 5.9)
It also seems to break for me as soon as i tab out of my Terminal and tab back in.
@ozwaldorf @iroedius @rayjanoka @CaptainJack42
Can you please do the following?
rm -rf $_autocomplete__log $_autocomplete__log_async $_autocomplete__log_pty
functions -t $_autocomplete__log_functions[@]
$_autocomplete__log
, $_autocomplete__log_async
and $_autocomplete__log_pty
@marlonrichert Here are the log files. It took a pretty long time to reproduce this time, however i now found a method to reproduce it relatively consistent:
cd /path/to/some/folder/foo/bar/
) and don't press enter.zsh-syntax-highlighting
will also break, however only for this specific line and when typing something new syntax highlighting will work again).Hope i can help with this.
@CaptainJack42 Thanks! This is the offending line:
.autocomplete.recent_paths.add:shift:16: shift count must be <= $#
So, judging from the surrounding code, it appears that $displ[@]
has fewer elements than $matches[@]
.
However, I'm still unable to reproduce any of this. 🙁
Good to see an issue open on this. I thought I'm a lonely poor mofo who unknowingly broke his system and now can't find a solution. Basically just a little bump to this issue, that it also can be verified on the machine I'm using.
@tobealive Can you try to put together a test case that I can use to reproduce the problem? So far, I have not been able to.
Hi @marlonrichert, when I have some minutes I could try to provide a scenario using a VM with a liveboot or clean install. To be sure it is something reproducible.
Would that be something of use to you or too much of a hassle to find a solution?
@tobealive I don’t have anything set up to run VMs, but if you can provide clear instructions on how to run it, then yes, that would be useful.
Not a VM but, a docker file
Create a file called Dockerfile
in a empty directory.
FROM archlinux:base-devel
RUN pacman --needed --noconfirm -Syu pacman-contrib git zsh
# Add non-root user
RUN useradd -m builder && \
echo 'builder ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers
# Switch user and cwd
USER builder
WORKDIR /home/builder
And then in the same folder run
sudo docker build -t nodebb .
sudo docker run -it --entrypoint /bin/zsh nodebb
And then zsh comfiguration screen will pop up, complete it.
Next do:
cd $(mktemp -d)
git clone --depth 1 -- https://github.com/marlonrichert/zsh-autocomplete.git
> .zshrc <<EOF
PS1='%# ' PS2= RPS2='%^'; setopt transientrprompt interactivecomments
source ~/zsh-autocomplete/zsh-autocomplete.plugin.zsh
EOF
env -i HOME=$PWD PATH=$PATH TERM=$TERM ${TERMINFO:+TERMINFO=$TERMINFO} zsh -d
And do what https://github.com/marlonrichert/zsh-autocomplete/issues/441#issuecomment-1160331716 says to reproduce the scenario. I personally can reproduce it just by typing cd zsh-autocomlete
individually, and delete the command by holding backspace.
@KyleUltimate Thanks! I'm able to reproduce it with this. 🥳
...but now I'm again unable to reproduce it. I managed to reproduce it only once and completely by accident. Not sure what steps I did that caused it. 😕
Even after reentering the docker? (exit
and do the docker run again)
Nope. Can you give me a path in the Docker environment with which you are able to reproduce the problem?
File... path?
I don't quite understand what you mean. If you mean where zsh-complete
is, it's just in the
@KyleUltimate These are the steps to reproduce in the comment you linked to:
- Type/Autocomplete a relatively long command/path (e.g
cd /path/to/some/folder/foo/bar/
) and don't press enter.- Delete the command by holding backspace.
- At some point during the deletion process the plugin will break (i am able to notice the point since at the same point
zsh-syntax-highlighting
will also break, however only for this specific line and when typing something new syntax highlighting will work again).
So, I need a sufficiently long directory path to reproduce to reproduce it. So far, I have not been able to find one.
/usr/share/gdb/auto-load/usr/lib/libglib-2.0.so.0.7200.2-gdb.py
(for me, 99% of the time the completion disappear midway typing through libglib...)
@marlonrichert
So, I need a sufficiently long directory path to reproduce to reproduce it. So far, I have not been able to find one.
I also can't reproduce it with the existing directories in the docker container, but just creating a very long path inside the docker container (e.g. mkdir -p sth-long/very-long-directory-name/tmp/foo/bar/very-nice-name/extremely-long-path/user/projects/foo/bar/dir/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z
) and than trying to autocomplete cd
into this directory will either break the plugin while repeatedly pressing tab
or when deleting the whole thing again by holding backspace
.
However it is significantly harder to break the plugin in the docker container than on my system.
One very uneducated guess to why this is happening is that at a certain point is that the autocompletions change to quickly and the system can't keep up with it anymore and the plugin breaks.
Edit: Also resourcing the .zshrc
(or just the zsh-autocomplete.plugin.zsh
) will fix the issue.
Update: My very uneducated guess was wrong. I tried to reproduce it on my convertible Laptop (running Linux Mint with Kernel v5.4, i3-6100U CPU and 4GB of RAM) and was unable to reproduce it with and without (which isn't really surprising since it's running zsh v5.8) the docker file.
So it seems to only be an issue with newer Kernels or arch-based Kernels (and macOS from what other commenters said), so far i've only noticed the issue on anything arch-based (tried it on Manjaro, Arch and Arcolinux so far). It's also independent from the Terminal Emulator (same issue with Konsole, xfce4-terminal and Terminator).
I can try and provide a setup for a VM to reproduce the issue in a bit.
Edit: Also resourcing the
.zshrc
(or just thezsh-autocomplete.plugin.zsh
) will fix the issue.
Thanks, that gives a good clue. Based on that, my guess is that the internal state of Zsh Autocomplete gets messed up somewhere because of concurrent modification.
Zsh does not have a native way of ensuring thread safety. In fact, it does not have threads at all: For example, if a Trap occurs during an asynchronous callback, the operations from both codes will run interleaved inside your shell session and can access (and thus overwrite) each other's variables. 😱
I'll have to see if I can implement some kind of locking mechanism. Patches welcome, of course. 🙂
@ozwaldorf @iroedius @rayjanoka @CaptainJack42 @tobealive @KyleUltimate
Can you try the following?
functions -T .autocomplete.async.complete .autocomplete.zle-flags
.@marlonrichert
Hoping this helps (didn't really know what you menat with activate autocompletion once, but i just typed cd
once after running functions -T ...
)
Output after plugin stopped working, running functions -T .autocomplete.async.complete .autocomplete.zle-flags
and cd
:
Thanks! I’ll have to analyze this a bit further. At least from a quick glance, it looks like in @KyleUltimate’s & @tobealive’s case, the callback function is never reached.
As a workaround, can you try increasing the value of this parameter from the default of 0.05 seconds?
Does that help?
Nope, still breaks.
this is what after cd zsh
tab happens.(with the autocomplete zstyle in zshrc)
@KyleUltimate To how much did you increase the value?
@CaptainJack42 @tobealive @KyleUltimate Can you try my instructions in https://github.com/marlonrichert/zsh-autocomplete/issues/441#issuecomment-1160300515, too?
To how much did you increase the value?
to 0.1
Also, I've successfully uncreated... the problem. It only breaks in a newly created zsh environment(the temp method) set to 0.1, after sourcing .zshrc
. But at my local zsh machine, it completely works file after I set it to 0.1.
Post edit, I can't create this problem anymore(no matter where I try). It seems like setting the min-delay to a higher value does have a good impact
Can you try my instructions in https://github.com/marlonrichert/zsh-autocomplete/issues/441#issuecomment-1160300515, too?
Sure, do I also need to change this zstyle ':autocomplete:*' min-delay 0.05 # float
too?
@marlonrichert
Still breaks with setting min delay
to 0.1 and 0.5.
Here's the output and also the 3 log files:
Thanks, that's interesting output. It looks like the async completion does finish successfully, but for some reason, the callback widget is never triggered. I wonder if the callback/file descriptor gets unhooked/closed prematurely.
Can you try the following?
PS4=$_autocomplete__ps4
setopt promptsubst
functions -t .autocomplete.async.stop .autocomplete.async.start
@marlonrichert
Here's the output.
The bug appeared after the usual cd into/long/path
and than deleting the command by holding backspace
.
Thanks. It didn’t produce any useful output, though.
a small question, with Autosuggestion stops working
do you mean the fish-like type ahead autosuggestion? If yes I can report that on debian linux-gnu /usr/bin/zsh debian/5.8-6+deb11u1
this is also not working
It seems like the commit b0bd14035
(2021-04-21) for zsh is the first one which yields this behavior (the previous commit e7711e37e
of zsh did not produce this bug). This commit changed zmathfunc
, so maybe a calculation (in zsh-autocomplete) is erroneous?
Edit: Interestingly, trying to debug it, using set -x and a trap function to redirect the debug output to a file, did not produce any results because the bug no longer occurred. The only change should be the increased delay due to debugging.
Here are few of my log files.
2022-08-04.pty.log 2022-08-09.pty.log 2022-08-11.pty.log 2022-08-10.pty.log 2022-08-05.log
@blueray453 They show a lot of input/output errors. What were you trying to complete?
The terminal kept closing down (goes away) in the middle of my work (automatically triggering suggestion functions which have bugs). Then i went through the code and found that there are logs. I checked the logs and they are not descriptive. They do not say, which error, when, what etc. At some point the extension became unusable.
Then i came up with my own completion taking hint from your extension.
# Should be called before compinit
zmodload zsh/complist
autoload -Uz compinit && compinit
zstyle ':completion:*' use-cache on
zstyle ':completion:*' accept-exact '*(N)'
compdef _gnu_generic bat
compdef _gnu_generic broot
compdef br=broot
compdef _gnu_generic exa
compdef _gnu_generic fd
# compdef _gnu_generic lf
compdef _gnu_generic rg
compdef _gnu_generic sd
compdef _gnu_generic rofi
# show modified files in completion
zstyle ':completion::complete:git-diff*:argument-rest:tree-files' command 'git ls-files -m'
# Change tag order
zstyle :completion::complete:git-diff:argument-rest: group-order modified-files files
zstyle :completion::complete:git-difftool:argument-rest: group-order modified-files files
setopt MENU_COMPLETE # Automatically highlight first element of completion menu
setopt AUTO_LIST # Automatically list choices on ambiguous completion.
setopt COMPLETE_IN_WORD # Complete from both ends of a word.
# Define completers
# zstyle ':completion:*' completer _expand _alias _complete _ignored
zstyle ':completion:*' completer _extensions _complete _approximate
# menu selection
zstyle ':completion:*' menu yes select=2 # select completions with arrow keys
zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
zstyle ':completion:*:*:*:*:corrections' format '%F{yellow}!- %d (errors: %e) -!%f'
zstyle ':completion:*:*:*:*:descriptions' format '%F{blue}-- %D %d --%f'
zstyle ':completion:*:*:*:*:messages' format ' %F{purple} -- %d --%f'
zstyle ':completion:*:*:*:*:warnings' format ' %F{red}-- no matches found --%f'
zstyle ':completion:*:default' list-prompt '%S%M matches%s'
zstyle ':completion:*' max-errors 2
# Colors for files and directory
zstyle ':completion:*:*:*:*:default' list-colors ${(s.:.)LS_COLORS}
# Kill Command
zstyle ':completion:*:kill:*' command 'ps -u $USER -o pid,%cpu,tty,cputime,cmd'
# Only display some tags for the command cd
zstyle ':completion:*:*:cd:*' tag-order local-directories directory-stack path-directories
# Required for completion to be in good groups (named after the tags)
zstyle ':completion:*' group-name '' # group results by category
zstyle ':completion:*:*:-command-:*:*' group-order aliases builtins functions commands
# See ZSHCOMPWID "completion matching control"
zstyle ':completion:*' matcher-list '' 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
zstyle ':completion:*' keep-prefix true
zstyle -e ':completion:*:(ssh|scp|sftp|rsh|rsync):hosts' hosts 'reply=(${=${${(f)"$(cat {/etc/ssh_,~/.ssh/known_}hosts(|2)(N) /dev/null)"}%%[# ]*}//,/ })'
bindkey "^U" history-substring-search-down
zstyle ':completion:*' insert-tab false
# complete man pages
zstyle ':completion:*:manuals' separate-sections true
zstyle ':completion:*:manuals.(^1*)' insert-sections true
zstyle ':completion:*' list-separator '#'
It is serving me very well. It is also compatible with both
https://github.com/zsh-users/zsh-autosuggestions https://github.com/zsh-users/zsh-history-substring-search
I am not an expert and sure there are few issues with this config. Please give the configs which your extension renders to. That way i would be able to make mine better.
For me, this issue also occurs when calling the history a few times.
Steps to reproduce
OS: EndeavourOS Linux x86_64
Kernel: 6.0.2-arch1-1
Uptime: 16 hours, 2 mins
Packages: 2269 (pacman), 28 (flatpak)
Shell: zsh 5.9
Resolution: 3440x1440, 3440x1440, 1080x1920, 1080x1920
WM: awesome
Theme: Catppuccin-Mocha [GTK2/3]
Icons: candy-icons [GTK2/3]
Terminal: kitty
CPU: AMD Ryzen 7 5800X (16) @ 3.800GHz
GPU: AMD ATI Radeon RX 6700/6700 XT/6750 XT / 6800M
Memory: 9664MiB / 32011MiB
Edit: Downgrading zsh to 5.8.1 works flawlessly
I'm still unable to reproduce this, not on my Intel Mac and not on my Intel PC running Ubuntu.
Is there anyone here who could try to debug this?
I'm still unable to reproduce this, not on my Intel Mac and not on my Intel PC running Ubuntu.
Is there anyone here who could try to debug this?
I think I might have found the problem.
scripts/.autocomplete.async line 214
I changed it from
zselect -t "$(( [#10] 100 * max( 0, min_delay - SECONDS ) ))"
to
zselect -t "$(( [#10] 100 * 0.05 ))
and havent had an issue since.
I don't know what other issue this may cause, but as @Mordna pointed out about zmathfunc, I focused on all min/max calls and just tried changing stuff randomly :-D)
zselect -t "$(( [#10] 100 * 0.05 ))"
it does seem like that did the trick! thx @ad-on-is
zselect -t "$(( [#10] 100 * 0.05 ))"
it does seem like that did the trick! thx @ad-on-is
I'd still suggest @marlonrichert to take a look at it.. the line should probably be something like:
zselect -t "$(( [#10] 100 * min_delay ))
, since min_delay is configurable.
doesn't seem to happen with zsh 5.8
Environment
Steps to reproduce
there will be no suggestion for the final
cd