ibhagwan / fzf-lua

Improved fzf.vim written in lua
MIT License
2.39k stars 152 forks source link

live_grep() stuck doesn't prompt anything #510

Closed giovanism closed 2 years ago

giovanism commented 2 years ago

Info

fzf-lua configuration ```lua require('fzf-lua').setup({ }) ```

Description

It's been sometime that I'm unable to use live_grep(). Digging deeper this is seemed to be caused by git_icons and file_icons opts. I'm not sure yet what's beyond that.

image
ibhagwan commented 2 years ago

It's been sometime that I'm unable to use live_grep(). Digging deeper this is seemed to be caused by git_icons and file_icons opts. I'm not sure yet what's beyond that.

If the answer to the last quesion is yes, does running git rev-parse --show-toplevel in the shell (inside a git repo) work in a resonable time?

giovanism commented 2 years ago
Q A
Does live_grep_native work? Works
Does :FzfLua live_grep git_icons=false work? Doesn't work
Does :FzfLua live_grep file_icons=false work? Works using mini.sh env, also Works on my own config outside git repo, but Doesn't work on my own config inside git repo.
Does :FzfLua files git_icons=false work? Works
Does :FzfLua files file_icons=false work? Works
Is there any difference between running the command inside/outside of a git repo? Explained above for affected case

Does :FzfLua live_grep git_icons=false work?

Felt like it worked at first in some case (e.g. outside git repo), but as i tried it again a coupe of times, it doesn't work. Is there a way I can clear cache on the mini.sh env? to attempt it fresh, or correct me if there's no such a thing.

❯ time git rev-parse --show-toplevel
/Users/$USER/.local/share/nvim/site/pack/packer/start/fzf-lua
git rev-parse --show-toplevel  0.00s user 0.00s system 45% cpu 0.014 total
ibhagwan commented 2 years ago

Is there a way I can clear cache on the mini.sh

look at the output of the command and rm -rf the temp folder fzf-lua.tmp, it will be recreated again fresh.

Can you try with multiprocess=false and see if there’s any difference?

giovanism commented 2 years ago

Felt like it worked at first in some case (e.g. outside git repo), but as i tried it again a coupe of times, it doesn't work. Is there a way I can clear cache on the mini.sh env? to attempt it fresh, or correct me if there's no such a thing.

Ok. I was tripping. It did not work.

multiprocess=false

Yup, having multiprocess=false works for mini.sh and my config.

ibhagwan commented 2 years ago

Yup, having multiprocess=false works for mini.sh and my config.

Ok, so we now know the issue lies with the headless neovim wrapper, can you run :FzfLua live_grep debug=true, then copy paste the long command from :messages, delete the _G.fzf_lua_server part and run it in the shell and see if it works?

giovanism commented 2 years ago

Yup it works. Although for me since I used zsh there's some escaping needed for the angle brackets (<> kinda unrelated).

image
ibhagwan commented 2 years ago

Yup it works. Although for me since I used zsh there's some escaping needed for the angle brackets (<> kinda unrelated).

My suspicion is on the RPC connection between the neovim instances (main + headless), can you try with the fzf_lua_server? Just have to make sure the neovim instance that printed the debug command is still open so that the RPC connection has a destination.

giovanism commented 2 years ago

The first one was when the nvim instance still running, and later when closed

image
ibhagwan commented 2 years ago

The first one was when the nvim instance still running, and later when closed

Seems to work as expected, when the neovim instance is closed it cannot retrieve fzf-lua’s configuration and prints the connection refused errors.

I’ll dig more into the multiprocess code to get some more educated guesses where the hang might lie, what confuses me more is why this happens only with live grep, does it work perfectly with files with both git and files icons inside and outside a git repo? Do the files/git icons render properly (modified, etc)?

ibhagwan commented 2 years ago

Can you try both the below, let me know which work and which doesn't and post the debug command from :mesages?

:lua require'fzf-lua'.files({git_icons=false, file_icons=false, requires_processing=true, debug=true})
:lua require'fzf-lua'.live_grep({git_icons=false, file_icons=false, requires_processing=true, debug=true})
-- according to our previous testing, these should work and not produce a command in `:messages`
:lua require'fzf-lua'.files({git_icons=false, file_icons=false, multiprocess=false, debug=true})
:lua require'fzf-lua'.live_grep({git_icons=false, file_icons=false, multiprocess=false, debug=true})
giovanism commented 2 years ago
result debug :messages
Works '/opt/homebrew/Cellar/neovim/0.7.2_1/bin/nvim' -n --headless --clean --cmd 'lua loadfile([[/var/folders/bg/zhngdn4s4bd756yqgq4923dc0000gp/T/fzf-lua.tmp/nvim/site/pack/vendor/start/fzf-lua/lua/fzf-lua/libuv.lua]])().spawn_stdio({debug=true,cmd=[[rg --color=never --files --hidden --follow -g '\''!.git'\'']],git_icons=false,file_icons=false,color_icons=true},[[_G._devicons_path='\''/var/folders/bg/zhngdn4s4bd756yqgq4923dc0000gp/T/fzf-lua.tmp/nvim/site/pack/vendor/start/nvim-web-devicons/lua/nvim-web-devicons.lua'\''; _G._fzf_lua_server='\''/var/folders/bg/zhngdn4s4bd756yqgq4923dc0000gp/T/nvim6NznGo/1'\''; return require("make_entry").file]],[[return require("make_entry").preprocess]])'
Doesn't work '/opt/homebrew/Cellar/neovim/0.7.2_1/bin/nvim' -n --headless --clean --cmd 'lua loadfile([[/var/folders/bg/zhngdn4s4bd756yqgq4923dc0000gp/T/fzf-lua.tmp/nvim/site/pack/vendor/start/fzf-lua/lua/fzf-lua/libuv.lua]])().spawn_stdio({debug=true,argv_expr=true,cmd=[[rg --column --line-number --no-heading --color=always --smart-case --max-columns=512 <query> ]],git_icons=false,file_icons=false,color_icons=true,__module__=[[grep]]},[[_G._devicons_path='\''/var/folders/bg/zhngdn4s4bd756yqgq4923dc0000gp/T/fzf-lua.tmp/nvim/site/pack/vendor/start/nvim-web-devicons/lua/nvim-web-devicons.lua'\''; _G._fzf_lua_server='\''/var/folders/bg/zhngdn4s4bd756yqgq4923dc0000gp/T/nvimKIk8qN/1'\''; return require("make_entry").file]],[[return require("make_entry").preprocess]])'
Works
Works

Interesting that the hang is not directly caused by the git or file icons opts.

ibhagwan commented 2 years ago

Interesting that the hang is not directly caused by the git or file icons opts.

Also interesting that it doesn’t fail with fd only with rg… so confusing, what happens if we use grep?

:lua require'fzf-lua'.live_grep({cmd =  "grep --binary-files=without-match --line-number --recursive --color=auto --perl-regexp", debug=true})
giovanism commented 2 years ago

Still hangs with this debug message

'/opt/homebrew/Cellar/neovim/0.7.2_1/bin/nvim' -n --headless --clean --cmd 'lua loadfile([[/var/folders/bg/zhngdn4s4bd756yqgq4923dc0000gp/T/fzf-lua.tmp/nvim/site/pack/vendor/start/fzf-lua/lua/fzf-lua/libuv.lua]])().spawn_stdio({debug=true,argv_expr=true,cmd=[[grep --binary-files=without-match --line-number --recursive --color=auto --perl-regexp <query> ]],git_icons=false,file_icons=true,color_icons=true,__module__=[[grep]]},[[_G._devicons_path='\''/var/folders/bg/zhngdn4s4bd756yqgq4923dc0000gp/T/fzf-lua.tmp/nvim/site/pack/vendor/start/nvim-web-devicons/lua/nvim-web-devicons.lua'\''; _G._fzf_lua_server='\''/var/folders/bg/zhngdn4s4bd756yqgq4923dc0000gp/T/nvimWfKxe2/1'\''; return require("make_entry").file]],[[return require("make_entry").preprocess]])'

ibhagwan commented 2 years ago

Still hangs with this debug message

ok, so it’s something to do with the live grep code and not related to the rg binary, I think this gives me enough pointers to try and isolate the issue.

If my assumptions are correct that would mean grep and grep_project are working fine and the issue is only with live grep, is that correct?

ibhagwan commented 2 years ago

I have a strong suspection your shell has issues with the query placeholder which is surrounded by <>, not sure why your environment spefically but we'll get to the why if we can prove this is the issue :-)

Can you test with branch 510?

giovanism commented 2 years ago

Tested and still stuck. with this debug messages '/opt/homebrew/Cellar/neovim/0.7.2_1/bin/nvim' -n --headless --clean --cmd 'lua loadfile([[/Users/giovan.musthofa/.local/share/nvim/site/pack/packer/start/fzf-lua/lua/fzf-lua/libuv.lua]])().spawn_stdio({debug=true,argv_expr=true,cmd=[[rg --column --line-number --no-heading --color=always --smart-case --max-columns=512 {query} ]],git_icons=false,file_icons=true,color_icons=true,__module__=[[grep]]},[[_G._devicons_path='\''/Users/giovan.musthofa/.local/share/nvim/site/pack/packer/start/nvim-web-devicons/lua/nvim-web-devicons.lua'\''; _G._fzf_lua_server='\''/var/folders/bg/zhngdn4s4bd756yqgq4923dc0000gp/T/nvim3JQn7G/1'\''; return require("make_entry").file]],[[return require("make_entry").preprocess]])'

I don't think fzf exec through shell, and zsh is pretty common shell. Is this only happening to me or you as well? Because live_grep looks like a pretty popular/mostly used built ins.

Or are you saying this is not default behavior of zsh?

k8s:N/A:default ~/tmp❯ touch <>
zsh: parse error near `\n'
k8s:N/A:default ~/tmp❯ ls
hello.txt
k8s:N/A:default ~/tmp❯ touch \<\>
k8s:N/A:default ~/tmp❯ ls
<>        hello.txt
k8s:N/A:default ~/tmp❯
giovanism commented 2 years ago

If my assumptions are correct that would mean grep and grep_project are working fine and the issue is only with live grep, is that correct?

Yes and yes. Damn never knew grep_project is also interactive or live i would say.

ibhagwan commented 2 years ago

I don't think fzf exec through shell, and zsh is pretty common shell. Is this only happening to me or you as well? Because live_grep looks like a pretty popular/mostly used built ins.

This is only happening to you, otherwise this issue would be swamped, live_grep is one of the most common uses and if this would fail before I would've fixed (or no one would use this plugin), this is the first time I encountered this issue.

Yes and yes. Damn never knew grep_project is also interactive or live i would say.

grep_project and live_grep aren't the same, although they are complmentary, live_grep passes the regex as is to rg and returns exact matches, grep_project runs an empty search rg, feeds all the lines to fzf and then fuzzy matches on top (and you can switch back and forth between them using <C-g>): https://github.com/ibhagwan/fzf-lua/wiki#grep-vs-live-grep

Try the above with multiprocess=false (which is working for you) and you'll understand the difference between live grep and grep and also the power that comes from being able to refine your regex and then fuzzy match on top.

Or are you saying this is not default behavior of zsh?

I'm actually suspecting your sh as fzf-lua runs the initial command using sh -c, also, your test isn't accurate as the <> are wrapped inside single quotes.

I'm still not sure if this is even the issue, perhaps there was an upgrade to sh with macOS Monterey 12.3.1?

ibhagwan commented 2 years ago

Just tested succefully on MacOS Monterey 12.5.1 with the following binaries:

~ ❯ zsh --version
zsh 5.8.1 (x86_64-apple-darwin21.0)
~ ❯ sh --version
GNU bash, version 3.2.57(1)-release (arm64-apple-darwin21)
Copyright (C) 2007 Free Software Foundation, Inc.
~ ❯ fzf --version
0.33.0 (brew)

I'm questining the theory that either shell is the issue here, given this is only happening to you I'm thinking this might be related to your environment, would you be able to test with a barebone zsh/bash/sh with no environment variables (i.e. no .profile, .bash_profile, .zshrc, etc)?

skwee357 commented 2 years ago

Hey. Just wanted to let you know, I have the same issue.

MacOS Monterey 12.5.1 zsh shell Alacritty terminal nvim 0.7.0 fzf 0.30.0 (brew) rg -V 13.0.0

ibhagwan commented 2 years ago

@skwee357, few questions:

skwee357 commented 2 years ago

@ibhagwan Hey, thanks for looking into this. Here are the answers:

~ ❯ sh --version                                             
GNU bash, version 3.2.57(1)-release (arm64-apple-darwin21)
Copyright (C) 2007 Free Software Foundation, Inc.

~ ❯ zsh --version
zsh 5.8.1 (x86_64-apple-darwin21.0)

~ ❯ luajit -v
LuaJIT 2.1.0-beta3 -- Copyright (C) 2005-2022 Mike Pall. https://luajit.org/

Ran export SHELL=/bin/bash and then nvim same behaviour.

:FzfLua live_grep exec_empty_query=true works, when I type it filters correctly.

Same happens on branch 510

ibhagwan commented 2 years ago

:FzfLua live_grep exec_empty_query=true works, when I type it filters correctly.

Ty @skwee357, this is key info.

I think I have the solution now, can you pull --rebase and try branch 510 again (commit https://github.com/ibhagwan/fzf-lua/commit/b7cf11bf13fad98f714d2b0e7227223bc61bb8b3)?

s-taylor commented 2 years ago

I had the same issue, but after updating it seems to be fixed. Thankyou!

ibhagwan commented 2 years ago

Ty for the confirmation @s-taylor, just merged https://github.com/ibhagwan/fzf-lua/commit/b7cf11bf13fad98f714d2b0e7227223bc61bb8b3 into main.

Will await further confirmations to close this issue just to be safe.

skwee357 commented 2 years ago

@ibhagwan Did :PlugUpdate and everything works on master now! Thank you very much 🙏

ibhagwan commented 2 years ago

@ibhagwan Did :PlugUpdate and everything works on master now! Thank you very much pray

Ty @skwee357, closing.