Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: "FzfLua buffers" shows preview on first call even if preview is disabled #1527

Closed
4 of 6 tasks
vdcow opened this issue Nov 15, 2024 · 24 comments · Fixed by #1528
Closed
4 of 6 tasks

Bug: "FzfLua buffers" shows preview on first call even if preview is disabled #1527

vdcow opened this issue Nov 15, 2024 · 24 comments · Fixed by #1528
Labels
bug Something isn't working upstream An issue upstream (neovim, fzf, etc)

Comments

@vdcow
Copy link

vdcow commented Nov 15, 2024

RTFM Checklist

  • I have searched exisiting issues / discussions
  • I have read the Wiki including the Advanced section
  • I have read man fzf / I am well versed in shell fzf

Operating system

Linux

Shell

bash

Neovim version (nvim --version)

0.10.2

Fzf version (fzf --version)

0.56.2

Output of :lua print(os.getenv('FZF_DEFAULT_OPTS'))

nil

Is the problem reproducible with mini.sh?

  • My issue is reproducible with mini.sh
  • My issue IS NOT reproducible with mini.sh
  • I have not tested with mini.sh (not relevant, requires LSP, Windows, etc)

Fzf-lua configuration

require('fzf-lua').setup({
{'max-perf',
	      buffers = {
		      no_lnum = true,
	      },
              winopts={
		      height           = 0.40,            -- window height
		      width            = 1,            -- window width
		      row              = 1,            -- window row position (0=top, 1=bottom)
		      col              = 0.50,            -- window col position (0=left, 1=right)
		      preview={hidden = "hidden"}
	      },
	      -- fzf '--color=' options (optional)
	      fzf_colors = {
		      ["fg"]          = { "fg", "CursorLine" },
		      ["bg"]          = { "bg", "Normal" },
		      ["hl"]          = { "fg", "Special" },
		      ["fg+"]         = { "fg", "Normal" },
		      ["bg+"]         = { "bg", "CursorLine" },
		      ["hl+"]         = { "fg", "Special" },
		      ["info"]        = { "fg", "PreProc" },
		      ["prompt"]      = { "fg", "Conditional" },
		      ["pointer"]     = { "fg", "Exception" },
		      ["marker"]      = { "fg", "Keyword" },
		      ["spinner"]     = { "fg", "Label" },
		      ["header"]      = { "fg", "Comment" },
		      ["gutter"]      = { "bg", "Normal" },
	       },
})

Describe the bug / steps to reproduce

In the latest versions of fzf-lua first call to ":FzfLua buffers" shows preview for files in the buffer list though I have preview disabled in the configuration. All next calls don't have preview window.

@vdcow vdcow added the bug Something isn't working label Nov 15, 2024
@vdcow
Copy link
Author

vdcow commented Nov 15, 2024

Note that even direct call

:FzfLua buffers winopts.preview.hidden="hidden"

has the same issue (first call shows the preview, all next calls don't).

@ibhagwan
Copy link
Owner

Note that even direct call

:FzfLua buffers winopts.preview.hidden="hidden"

has the same issue (first call shows the preview, all next calls don't).

Just tested and can’t reproduce this, perhaps something related to your config?

Try :FzfLua buffers winopts.preview.hidden=hidden with mini.sh?

@ibhagwan ibhagwan added invalid This doesn't seem right and removed bug Something isn't working labels Nov 15, 2024
@vdcow
Copy link
Author

vdcow commented Nov 15, 2024

@ibhagwan Couldn't reproduce with default init.lua but could reproduce with my config listed in the description.

@ibhagwan
Copy link
Owner

ibhagwan commented Nov 15, 2024

@ibhagwan Couldn't reproduce with default init.lua but could reproduce with my config listed in the description.

Then debug your config to see where the issue stems from.

@vdcow
Copy link
Author

vdcow commented Nov 15, 2024

It seems that "max-perf" profile is broken. Couldn't reproduce it with "default".

@vdcow
Copy link
Author

vdcow commented Nov 15, 2024

@ibhagwan

Then debug your condig to see where the issue stems from.

Just in case, I could reproduce this issue using mini.sh and "max-perf" profile.

@ibhagwan
Copy link
Owner

It seems that "max-perf" profile is broken. Couldn't reproduce it with "default".

I tried max- perf with my own config earlier and couldn’t reproduce it, I’ll do some more testing later.

@ibhagwan
Copy link
Owner

@ibhagwan

Then debug your condig to see where the issue stems from.

Just in case, I could reproduce this issue using mini.sh and "max-perf" profile.

Good enough, I’ll tackle this later today I hope.

@vdcow
Copy link
Author

vdcow commented Nov 15, 2024

Just in case, my init.lua for mini.sh I used

-- add temp path from scripts/mini.sh in case this is running locally
local tempdir = vim.trim(vim.fn.system([[sh -c "dirname $(mktemp -u)"]]))
local packpath = os.getenv("PACKPATH") or tempdir .. "/fzf-lua.tmp/nvim/site"
vim.cmd("set packpath=" .. packpath)

vim.o.termguicolors = true

require "fzf-lua".setup { {'max-perf' } }

vim.api.nvim_set_keymap("n", "<C-\\>", [[<Cmd>lua require"fzf-lua".buffers()<CR>]], {})
vim.api.nvim_set_keymap("n", "<C-k>", [[<Cmd>lua require"fzf-lua".builtin()<CR>]], {})
vim.api.nvim_set_keymap("n", "<C-p>", [[<Cmd>lua require"fzf-lua".files()<CR>]], {})
vim.api.nvim_set_keymap("n", "<C-l>", [[<Cmd>lua require"fzf-lua".live_grep_glob()<CR>]], {})
vim.api.nvim_set_keymap("n", "<C-g>", [[<Cmd>lua require"fzf-lua".grep_project()<CR>]], {})
vim.api.nvim_set_keymap("n", "<F1>", [[<Cmd>lua require"fzf-lua".help_tags()<CR>]], {})

require("fzf-lua").utils.info(
  "|<C-\\> buffers|<C-p> files|<C-g> grep|<C-l> live grep|<C-k> builtin|<F1> help|")

@ibhagwan
Copy link
Owner

Strange, just tried the same init.lua with max-perf with neovim 0.10.2 and nightly and can’t reproduce this, I would suspect FZF_DEFAULT_OPTS but you posted in the OP it’s empty.

@vdcow
Copy link
Author

vdcow commented Nov 15, 2024

@ibhagwan I could try to debug the issue myself next week but I need a little help since I don't have experience with Neovim plugins debugging. Could you point me to a place in the code to start digging - e.g. place where fzf-lua decides "show or don't show preview"?

@ibhagwan
Copy link
Owner

@ibhagwan I could try to debug the issue myself next week but I need a little help since I don't have experience with Neovim plugins debugging. Could you point me to a place in the code to start digging - e.g. place where fzf-lua decides "show or don't show preview"?

My first bet would be what comes in and out of config.normalize_opts, this is where the user options are layered, you can use _G.dump(opts.winopts) to see if the winopts object contains the preview.hidden value:

function M.normalize_opts(opts, globals, __resume_key)

Before that we could can you try with debug? It should print the fzf command into :messages and we will see if it contains hidden:

:FzfLua buffers winopts.preview.hidden=hidden debug=true

@vdcow
Copy link
Author

vdcow commented Nov 16, 2024

@ibhagwan In both cases (first when I see preview and next when I don't) have the same output

Dump of options is the following

{
  debug = true,
  ["winopts.preview.hidden"] = "hidden"
}

fzf command for first call

fzf --layout reverse --height 100% --info inline-right --ansi --header-lines 1 --preview VIMRUNTIME='/usr/share/nvim/runtime' '/usr/bin/nvim' -n --headless --clean --cmd 'lua vim.g.did_load_filetypes=1; loadfile([[/home/cow/.local/share/nvim/lazy/fzf-lua/lua/fzf-lua/shell_helper.lua]])().rpc_nvim_exec_lua({fzf_lua_server=[[/run/user/500/fzf-lua.1731746397.45159.0]], fnc_id=4 , debug=true})' -- {} --header :: <?[38;2;166;219;255mctrl-x?[0m> to ?[38;2;224;226;234m?[48;2;20;22;27mclose?[0m --prompt Buffers>  --tiebreak index --border none --bind alt-g:last,alt-a:toggle-all,f3:toggle-preview-wrap,shift-down:preview-page-down,alt-shift-up:preview-up,ctrl-b:half-page-up,shift-up:preview-page-up,ctrl-f:half-page-down,ctrl-e:end-of-line,f4:toggle-preview,load:rebind(ctrl-x),ctrl-u:unix-line-discard,ctrl-x:unbind(ctrl-x)+execute-silent(VIMRUNTIME='/usr/share/nvim/runtime' '/usr/bin/nvim' -n --headless --clean --cmd 'lua vim.g.did_load_filetypes=1; loadfile([[/home/cow/.local/share/nvim/lazy/fzf-lua/lua/fzf-lua/shell_helper.lua]])().rpc_nvim_exec_lua({fzf_lua_server=[[/run/user/500/fzf-lua.1731746397.45159.0]], fnc_id=5 , debug=true})' -- {+})+reload(VIMRUNTIME='/usr/share/nvim/runtime' '/usr/bin/nvim' -n --headless --clean --cmd 'lua vim.g.did_load_filetypes=1; loadfile([[/home/cow/.local/share/nvim/lazy/fzf-lua/lua/fzf-lua/shell_helper.lua]])().rpc_nvim_exec_lua({fzf_lua_server=[[/run/user/500/fzf-lua.1731746397.45159.0]], fnc_id=3 , debug=true})' -- {+}),ctrl-z:abort,alt-G:first,alt-shift-down:preview-down,ctrl-a:beginning-of-line,resize:transform([ $FZF_COLUMNS -le 120 ] && echo change-preview-window:down:45% || echo change-preview-window:right:60%),alt-Q:print(alt-Q)+accept,ctrl-s:print(ctrl-s)+accept,ctrl-t:print(ctrl-t)+accept,ctrl-v:print(ctrl-v)+accept,ctrl-q:print(ctrl-q)+accept,ctrl-c:print(ctrl-c)+accept,alt-q:print(alt-q)+accept,esc:print(esc)+accept,enter:print(enter)+accept --preview-window hidden:border:nowrap:right:60%:+{2}-/2 --highlight-line --color info:#e0e2ea,fg+:#e0e2ea,bg+:#2c2e33,hl+:#8cf8f7,prompt:#e0e2ea,pointer:#e0e2ea,marker:#e0e2ea,gutter:#14161b,bg:#14161b,header:#9b9ea4,spinner:#e0e2ea,hl:#8cf8f7 --multi --delimiter [:] --print-query

For second call

fzf --layout reverse --height 100% --info inline-right --ansi --header-lines 1 --preview VIMRUNTIME='/usr/share/nvim/runtime' '/usr/bin/nvim' -n --headless --clean --cmd 'lua vim.g.did_load_filetypes=1; loadfile([[/home/cow/.local/share/nvim/lazy/fzf-lua/lua/fzf-lua/shell_helper.lua]])().rpc_nvim_exec_lua({fzf_lua_server=[[/run/user/500/fzf-lua.1731746397.45159.0]], fnc_id=8 , debug=true})' -- {} --header :: <?[38;2;166;219;255mctrl-x?[0m> to ?[38;2;224;226;234m?[48;2;20;22;27mclose?[0m --prompt Buffers>  --tiebreak index --border none --bind alt-g:last,alt-a:toggle-all,f3:toggle-preview-wrap,shift-down:preview-page-down,alt-shift-up:preview-up,ctrl-b:half-page-up,shift-up:preview-page-up,ctrl-f:half-page-down,ctrl-e:end-of-line,f4:toggle-preview,load:rebind(ctrl-x),ctrl-u:unix-line-discard,ctrl-x:unbind(ctrl-x)+execute-silent(VIMRUNTIME='/usr/share/nvim/runtime' '/usr/bin/nvim' -n --headless --clean --cmd 'lua vim.g.did_load_filetypes=1; loadfile([[/home/cow/.local/share/nvim/lazy/fzf-lua/lua/fzf-lua/shell_helper.lua]])().rpc_nvim_exec_lua({fzf_lua_server=[[/run/user/500/fzf-lua.1731746397.45159.0]], fnc_id=9 , debug=true})' -- {+})+reload(VIMRUNTIME='/usr/share/nvim/runtime' '/usr/bin/nvim' -n --headless --clean --cmd 'lua vim.g.did_load_filetypes=1; loadfile([[/home/cow/.local/share/nvim/lazy/fzf-lua/lua/fzf-lua/shell_helper.lua]])().rpc_nvim_exec_lua({fzf_lua_server=[[/run/user/500/fzf-lua.1731746397.45159.0]], fnc_id=7 , debug=true})' -- {+}),ctrl-z:abort,alt-G:first,alt-shift-down:preview-down,ctrl-a:beginning-of-line,resize:transform([ $FZF_COLUMNS -le 120 ] && echo change-preview-window:down:45% || echo change-preview-window:right:60%),alt-Q:print(alt-Q)+accept,ctrl-s:print(ctrl-s)+accept,ctrl-t:print(ctrl-t)+accept,ctrl-v:print(ctrl-v)+accept,ctrl-q:print(ctrl-q)+accept,ctrl-c:print(ctrl-c)+accept,alt-q:print(alt-q)+accept,esc:print(esc)+accept,enter:print(enter)+accept --preview-window hidden:border:nowrap:right:60%:+{2}-/2 --highlight-line --color info:#e0e2ea,fg+:#e0e2ea,bg+:#2c2e33,hl+:#8cf8f7,prompt:#e0e2ea,pointer:#e0e2ea,marker:#e0e2ea,gutter:#14161b,bg:#14161b,header:#9b9ea4,spinner:#e0e2ea,hl:#8cf8f7 --multi --delimiter [:] --print-query

@ibhagwan
Copy link
Owner

Both commands appear to contain --preview-window hidden (correct behavior), I’m thinking maybe the previewers are mixed up and you get the neovim previewer window to show somehow, can you post a screenshot of the first-call preview window?

@vdcow
Copy link
Author

vdcow commented Nov 17, 2024

@ibhagwan Screenshot (for max-perf)

image

Note that for default profile it looks different - takes proper colors from my init.lua when on the first screenshot default fzf colors are used

image

@ibhagwan
Copy link
Owner

Screenshot (for max-perf)

This looks correct, the fzf previewer is used which is very confusing why it would appear given the hidden property showing in the command line.

I’m suspecting the resize transform is what’s fishing this, can you set preview layout to either horizontal or vertical instead of the default flex?

@vdcow
Copy link
Author

vdcow commented Nov 17, 2024

@ibhagwan Indeed, using either horizontal or vertical layout resolves the issue.

@ibhagwan
Copy link
Owner

ibhagwan commented Nov 17, 2024

@ibhagwan Indeed, using either horizontal or vertical layout resolves the issue.

This makes sense, the resize event transformer (shell code) currently isn’t able to take into account the current state of the previewer (hidden / nohidden), this may be solved in the future with the introduction of more state variables in fzf, this is a known issue but unrelated to yours.

The below is the code bound to --bind=resize(…) (only when using flex layout), upon a terminal resize it will flip the preview rotation based on available columns:

local transformer = string.format(utils.__IS_WINDOWS
and "IF %%FZF_COLUMNS%% LEQ %d (echo change-preview-window:%s) "
.. "ELSE (echo change-preview-window:%s)"
or "[ $FZF_COLUMNS -le %d ] && echo change-preview-window:%s "
.. "|| echo change-preview-window:%s",

The question remaining is: why is your neovim triggering a terminal resize event when fzf-lua is opened for the first time?

I just tried installing fzf 0.56.2 (same neovim version already) and I still can’t reproduce this, unlikely, but perhaps this is related to your terminal app, what terminal are you using?

@vdcow
Copy link
Author

vdcow commented Nov 17, 2024

I am using Alacritty, but could reproduce the issue with Neovim QT, gnome terminal and even with xterm. So I don't think it is terminal specific.

@ibhagwan
Copy link
Owner

So I don't think it is terminal specific.

I didn’t think so either but had to try.

In any event, we know what the issue is and the workaround (do not use flex layout).

I will try to think of something to prevent the transform from showing the preview when hidden.

@ibhagwan ibhagwan added bug Something isn't working upstream An issue upstream (neovim, fzf, etc) and removed invalid This doesn't seem right labels Nov 17, 2024
@ibhagwan
Copy link
Owner

ibhagwan commented Nov 17, 2024

I'm thinking I can remove the transformer altogether and use alternative preview layout as was added in v0.31, for more info see junegunn/fzf#3817.

It might have other side effect so I'll have to do some testing, I also opened junegunn/fzf#4098 in case I'm missing something and we already have access to the preview hidden state.

Edit: Also opened junegunn/fzf#4100 as I found another issues with fzf auto layout rotation.

ibhagwan added a commit that referenced this issue Nov 18, 2024
Use alternative preview layout instead of using a "transform",
simpler, and we don't need to take into account the hidden state of
the preview as well as decrease the minimum fzf version for native
fzf flex layout to 0.31 (instead of 0.46).

Has known issue upstream where if the layout changes upon resize
the hidden state of the preview is lost:
junegunn/fzf#4100

Closes #1527
ibhagwan added a commit that referenced this issue Nov 18, 2024
Use alternative preview layout instead of using a "transform",
simpler, and we don't need to take into account the hidden state of
the preview as well as decrease the minimum fzf version for native
fzf flex layout to 0.31 (instead of 0.46).

Has known issue upstream where if the layout changes upon resize
the hidden state of the preview is lost:
junegunn/fzf#4100

Closes #1527
ibhagwan added a commit that referenced this issue Nov 18, 2024
Use alternative preview layout instead of using a "transform",
simpler, and we don't need to take into account the hidden state of
the preview as well as decrease the minimum fzf version for native
fzf flex layout to 0.31 (instead of 0.46).

Has known issue upstream where if the layout changes upon resize
the hidden state of the preview is lost:
junegunn/fzf#4100

Closes #1527
ibhagwan added a commit that referenced this issue Nov 18, 2024
Use alternative preview layout instead of using a "transform",
simpler, and we don't need to take into account the hidden state of
the preview as well as decrease the minimum fzf version for native
fzf flex layout to 0.31 (instead of 0.46).

Has known issue upstream where if the layout changes upon resize
the hidden state of the preview is lost:
junegunn/fzf#4100

Closes #1527
ibhagwan added a commit that referenced this issue Nov 18, 2024
Use alternative preview layout instead of using a "transform",
simpler, and we don't need to take into account the hidden state of
the preview as well as decrease the minimum fzf version for native
fzf flex layout to 0.31 (instead of 0.46).

Has known issue upstream where if the layout changes upon resize
the hidden state of the preview is lost:
junegunn/fzf#4100

Closes #1527
@ibhagwan
Copy link
Owner

@vdcow,

There's a fix for this issue pending in the refactor_flex branch, I'm still testing the various scenarios as I used this opportunity to further simplify the win object code but it looks good and should solve your issue.

The only thing I wasn't able to solve due to junegunn/fzf#4100 is the below scenario (somewhat insignificant):

  • Use flex layout
  • Open in a narrow term which opens the preview vertically (up|down)
  • Hide the preview using a keybind (F4 is the default)
  • Widen the terminal width beyond flip_columns value, the preview will rotate to a horizontal position (right/left) which is correct but will also unhide itself (due to the above upstream bug)

ibhagwan added a commit that referenced this issue Nov 19, 2024
Use alternative preview layout instead of using a "transform",
simpler, and we don't need to take into account the hidden state of
the preview as well as decrease the minimum fzf version for native
fzf flex layout to 0.31 (instead of 0.46).

Has known issue upstream where if the layout changes upon resize
the hidden state of the preview is lost:
junegunn/fzf#4100

Closes #1527
ibhagwan added a commit that referenced this issue Nov 19, 2024
Use alternative preview layout instead of using a "transform",
simpler, and we don't need to take into account the hidden state of
the preview as well as decrease the minimum fzf version for native
fzf flex layout to 0.31 (instead of 0.46).

Has known issue upstream where if the layout changes upon resize
the hidden state of the preview is lost:
junegunn/fzf#4100

Closes #1527
ibhagwan added a commit that referenced this issue Nov 19, 2024
Use alternative preview layout instead of using a "transform",
simpler, and we don't need to take into account the hidden state of
the preview as well as decrease the minimum fzf version for native
fzf flex layout to 0.31 (instead of 0.46).

Has known issue upstream where if the layout changes upon resize
the hidden state of the preview is lost:
junegunn/fzf#4100

Closes #1527
@ibhagwan
Copy link
Owner

@vdcow, 48f8a85 was merged, should solve this issue.

@vdcow
Copy link
Author

vdcow commented Nov 19, 2024

@ibhagwan Indeed, fix resolved the issue. Thank you! Really appreciate your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working upstream An issue upstream (neovim, fzf, etc)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants