ibhagwan / fzf-lua

Improved fzf.vim written in lua
GNU Affero General Public License v3.0
2.11k stars 138 forks source link

live_grep matches are not highlighted in preview or when selected #659

Closed benyn closed 1 year ago

benyn commented 1 year ago

Info

fzf-lua configuration ```lua require('fzf-lua').setup({ winopts = { preview = { default = "bat_async", }, }, grep = { cmd = "rg", file_icons = false, color_icons = false, git_icons = false, }, }) ```

Description

live_grep matches are not highlighted in preview. When selected, the file is opened but the cursor doesn't go to the matching line. This issue is NOT reproducible with mini.sh.

This might be related to the bat issue in #651

ibhagwan commented 1 year ago

Ty @benyn for opening a new issue for this, can you try the below, press Enter (on a failed file) and paste the output from :messages?

:lua require("fzf-lua").live_grep({actions={["default"]=function(sel) print("sel:", sel[1]) end}})

This issue is NOT reproducible with mini.sh

Usually when things break outside of mini.sh it is related to autocmd's set by the user or another plugin, can you check the output :autocmd BufEnter and :autocmd WinEnter for something suspecious?

benyn commented 1 year ago

This is what I got:

sel: nvim/lazy-lock.json:  "fzf-lua": { "branch": "main", "commit": "368b9980f7ddd9ee622cf84d0e7f96185a95bfc0" },

--- Autocommands ---
FileExplorer  BufEnter
    *         sil call s:LocalBrowse(expand("<amatch>"))
MiniAnimate  BufEnter
    *         lua vim.schedule(MiniAnimate.track_scroll_state)
lualine  BufEnter
    *         lua require'lualine.components.branch.git_branch'.find_git_dir()
              lua require'lualine.components.diff.git_diff'.update_diff_args()
lualine_stl_refresh  BufEnter
    *         call v:lua.require'lualine'.refresh({'kind': 'tabpage', 'place': ['statusline'], 'trigger': 'autocmd'})

--- Autocommands ---
MiniAnimate  WinEnter
    *         lua vim.schedule(MiniAnimate.track_scroll_state)
lualine_stl_refresh  WinEnter
    *         call v:lua.require'lualine'.refresh({'kind': 'tabpage', 'place': ['statusline'], 'trigger': 'autocmd'})

I got suspicious of MiniAnimate, and disabled it, but it's still not working.

ibhagwan commented 1 year ago

sel: nvim/lazy-lock.json: "fzf-lua": { "branch": "main", "commit": "368b9980f7ddd9ee622cf84d0e7f96185a95bfc0" },

There are no line/column output to your matches, I'm suspecting this is again due to the default non-GNU grep on MacOS fixed in https://github.com/ibhagwan/fzf-lua/commit/38cbc46a9c3516042e2560f56116c1410ddc4167 but unrelated to this issue.

ibhagwan commented 1 year ago

Scrap what I said, the issue is that you defined your grep command as rg with no flags at all so it doesn't ouput lines/columns and since the output doesn't contain these fzf-lua doesn't know where to go.

Your setup should look like:

require('fzf-lua').setup({
  winopts = { ... },
  grep = {
    -- modify these options to your liking but don't remove lines or columns
    -- color_icons is also not needed since you disabled the icons
    cmd = "rg --column --line-number --no-heading --color=always",
    file_icons = false,
    git_icons = false,
  },
})

FYI, by default fzf-lua autodetets rg and uses it with these options:

rg --column --line-number --no-heading --color=always --smart-case --max-columns=4096

Unless you have a specific reasoning behind ovewriting these flags I would remove the cmd = "rg .." part altogether from your setup.

benyn commented 1 year ago

Ah, that makes perfect sense. What you suggested works. I just got rid of cmd altogether since fzf-lua defaults to rg when available. I added it when I was trying out different configurations to fix #651 and didn't think to remove it. Ha, I just saw you edited your answer and suggested I remove cmd altogether as I was writing that sentence. ;)

This also explains whey rg_opts didn't work when I added --trim there in addition to cmd. Guess rg_opts is ignored when cmd is overridden? Anyway, thanks for responding to this quickly.

ibhagwan commented 1 year ago

This also explains whey rg_opts didn't work when I added --trim there in addition to cmd. Guess rg_opts is ignored when cmd is overridden? Anyway, thanks for responding to this quickly.

Correct, cmd takes precedence over everything else, rg_opts is only used with ”auto-detect” defaults.

benyn commented 1 year ago

Makes sense. A minor observation: README.md says --max-columns=512 instead of 4096.

ibhagwan commented 1 year ago

Makes sense. A minor observation: README.md says --max-columns=512 instead of 4096.

Thanks! I’ll update it next time, or if you want to be a contributor you can submit a PR :)

benyn commented 1 year ago

Haha, it's such a minor thing to contribute, but why not, I feel quite invested in fzf-lua now. Just submitted a PR.