ibhagwan / fzf-lua

Improved fzf.vim written in lua
MIT License
2.31k stars 150 forks source link

Live grep with fails on NixOS when `multiprocess=true` #291

Closed winston0410 closed 2 years ago

winston0410 commented 2 years ago

I have updated fzf-lua yesterday, and I found that live grep stopped working without any error. It cannot find any files in the directory now:

My config:

--  Potential issue here when reinstalling
local function getCwd()
    local path = require("fzf-lua.path").git_root(vim.loop.cwd(), true) or vim.loop.cwd()
    local header = ('--header="cwd = %s"'):format(vim.fn.shellescape(path))
    return { cwd = path, fzf_cli_args = header }
end

local function searchFiles()
    local opts = getCwd()

    require("fzf-lua").files(opts)
end

local function liveGrep()
    local opts = getCwd()

    require("fzf-lua").live_grep(opts)
end

local function init(use)
    use({
        "ibhagwan/fzf-lua",
        requires = {
            "vijaymarupudi/nvim-fzf",
            "kyazdani42/nvim-web-devicons",
        },
        config = function()
            local actions = require("fzf-lua.actions")

            require("fzf-lua").setup({
                winopts = {
                    win_height = 1,
                    win_width = 1,
                },
                fzf_layout = "reverse-list",
                files = {
                    prompt = "Fd❯ ",
                    --  Cannot set the cmd explicitly, as fzf-lua would not customize it further for you. Default to fd anyway
                    --  cmd = "fd",
                    git_icons = true, -- show git icons?
                    file_icons = true, -- show file icons?
                    color_icons = true, -- colorize file|git icons
                },
                grep = {
                    prompt = "Rg❯ ",
                    actions = {
                        ["Enter"] = actions.file_edit,
                    },
                },
            })

            for _, mode in ipairs({ "n", "v" }) do
                vim.api.nvim_set_keymap(mode, ",m", "<cmd>lua require('plugins.fzf-lua').searchFiles()<cr>", {
                    silent = true,
                    noremap = true,
                })

                vim.api.nvim_set_keymap(mode, ",pm", "<cmd>lua require('fzf-lua').files_resume()<cr>", {
                    silent = true,
                    noremap = true,
                })

                vim.api.nvim_set_keymap(mode, ",g", "<cmd>lua require('plugins.fzf-lua').liveGrep()<cr>", {
                    silent = true,
                    noremap = true,
                })

                vim.api.nvim_set_keymap(mode, ",pg", "<cmd>lua require('fzf-lua').live_grep_resume()<cr>", {
                    silent = true,
                    noremap = true,
                })

                vim.api.nvim_set_keymap(mode, ",a", "<cmd>lua require('fzf-lua').lsp_code_actions()<cr>", {
                    silent = true,
                    noremap = true,
                })

                vim.api.nvim_set_keymap(mode, ",a", "<cmd>lua require('fzf-lua').lsp_code_actions()<cr>", {
                    silent = true,
                    noremap = true,
                })

                vim.api.nvim_set_keymap(mode, ",s", "<cmd>lua require('fzf-lua').lsp_workspace_symbols()<cr>", {
                    silent = true,
                    noremap = true,
                })

                vim.api.nvim_set_keymap(mode, ",d", "<cmd>lua require('fzf-lua').lsp_workspace_diagnostics()<cr>", {
                    silent = true,
                    noremap = true,
                })
            end
        end,
    })
end

return {
    init = init,
    searchFiles = searchFiles,
    liveGrep = liveGrep,
}

Version of fzf-lua I am in:

~/.local/share/nvim/site/pack/packer/start/fzf-lua main
❯ git rev-parse HEAD
41b657e823f3f0fdfe199450e17fa1e893a1eaed

Maybe there is an update on directory setting? I am not really sure.

ibhagwan commented 2 years ago

No update should cause live_grep to stop functioning, given that I'm not sure when was your previous update let's try a few things:

For the last one, the first line should post the underlying rg command as the first result, can you run it in the shell and see if there are any results and also post it here?

ibhagwan commented 2 years ago

Btw, the below can be reduced due to a new option named show_cwd_header:

local function getCwd()
    local path = require("fzf-lua.path").git_root(vim.loop.cwd(), true) or vim.loop.cwd()
    local header = ('--header="cwd = %s"'):format(vim.fn.shellescape(path))
    return { cwd = path, fzf_cli_args = header }
end
local function getCwd()
    local path = require("fzf-lua.path").git_root(vim.loop.cwd(), true) or vim.loop.cwd()
    return { cwd = path, show_cwd_header = true }
end
winston0410 commented 2 years ago

Thank you so much for your reply. I have changed my code to show_cwd_header, but still it doesn't work.

This is the output of :lua require'fzf-lua'.live_grep({ multiprocess=true, debug=true })

'/etc/profiles/per-user/hugosum/bin/nvim' -n --headless --clean --cmd 'lua loadfile([[/home/hugosum/.loca
l/share/nvim/site/pack/packer/start/fzf-lua/lua/fzf-lua/libuv.lua]])().spawn_stdio({debug=true,cmd=[[rg -
-column --line-number --no-heading --color=always --smart-case --max-columns=512 {q} ]],git_icons=true,fi
le_icons=true,color_icons=true},[[_G._devicons_path='\''/home/hugosum/.local/share/nvim/site/pack/packer/
start/nvim-web-devicons/lua/nvim-web-devicons.lua'\''; _G._fzf_lua_server='\''/tmp/nvimZKSyGq/2'\''; retu
rn require("make_entry").file]],[[return require("make_entry").preprocess]])'

And live_grep_old is working perfectly fine. Not sure what went wrong during previous update there.

ibhagwan commented 2 years ago

And live_grep_old is working perfectly fine. Not sure what went wrong during previous update there.

That's great, at least you have an alternative.

I'd still like to understand why it's not working, did you happen to try with multiprocess = false?

The output of the debug command looks accurate, can you run it again with debug=true and then type in the search field, the first result should be a [DEBUG] line with the rg command generated by your typing, let me know if yours looks similar?

image

I modified the output of the command from your debug output a bit, can you run the below in the shell and let me know if you're seeing any results (the output should be rg with icons):

'/etc/profiles/per-user/hugosum/bin/nvim' -n --headless --clean --cmd 'lua loadfile([[/home/hugosum/.local/share/nvim/site/pack/packer/start/fzf-lua/lua/fzf-lua/libuv.lua]])().spawn_stdio({debug=true,cmd=[[rg --column --line-number --no-heading --color=always --smart-case --max-columns=512 a]],git_icons=true,file_icons=true,color_icons=true},[[_G._devicons_path='\''/home/hugosum/.local/share/nvim/site/pack/packer/start/nvim-web-devicons/lua/nvim-web-devicons.lua'\''; return require("make_entry").file]],[[return require("make_entry").preprocess]])'
winston0410 commented 2 years ago
  • lua require'fzf-lua'.live_grep({ multiprocess = false })

No I am being lazy, and I didn't tried the multiprocess = false. Tried it just now, and it is working. I guess the issue can be narrowed down to multiprocess = true

For running multiprocess = true, I get this, nothing really

1641244295

And for that command, I run it in shell and I get the output you have described like this:

1641244532

ibhagwan commented 2 years ago

For running multiprocess = true, I get this, nothing really

I think I see the issue here, althought the command isn't fully showing I can see you typed flake but the generated command shows let..., would you be able to run this again and let me know the full text of the DEBUG command?

I reduced the number of rg arguments so we will be able to see what's in the typed text better, you can also press <F2> to make fzf-lua fullscreen which will also help with visibilty:

:lua require'fzf-lua'.live_grep({ debug=true, cmd='rg --column --line-number' })
winston0410 commented 2 years ago

Unfortunately I haven't configure <F2> key in my macbook that runs NixOS lol I can't try that for you. But I have just tried that command, this is what I get:

1641245733

ibhagwan commented 2 years ago

Well this definitely confirms the bug, now I gotta figure out how on earth this can happen :-)

winston0410 commented 2 years ago

Sure no problem. Thank you for maintaining this!

ibhagwan commented 2 years ago

I think I found the issue, I suspect your NixOS supplies extra arguments to the neovim cli (python3 path in your case) which was messing up positional arguments I was relying upon for live_grep, I now use the last argument instead to store the query so hopefully this should work regardless of number of arguments supplied.

If this doesn't work can you run once again with debug=true? I added debug info which would give us information how many arguments were supplied and what is the last argument, this is how it should look like:

image

winston0410 commented 2 years ago

I have just updated and tried it again, and it is working perfectly fine! Thanks for your good work!

ibhagwan commented 2 years ago

Fantastic! tysm for the update and patience debugging this issue @winston0410