ibhagwan / fzf-lua

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

Bug: Error/freeze on FzfLua buffers #1365

Closed mikehaertl closed 3 months ago

mikehaertl commented 3 months ago

RTFM Checklist

Operating system

Linux Mint

Shell

bash

Neovim version (nvim --version)

NVIM v0.10.0

Fzf version (fzf --version)

81e7345

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

--color fg:7,bg:0,hl:13,fg+:2,bg+:6,hl+:13 --color query:13,info:12,prompt:13,spinner:3,marker:9 --cycle --bind=change:first,ctrl-n:page-down,ctrl-p:page-up,ctrl-t:toggle-preview,ctrl-alt-j:preview-down,ctrl-alt-k:preview-up,ctrl-alt-n:preview-page-down,ctrl-alt-p:preview-page-up,tab:accept,ctrl-o:toggle+d own,ctrl-alt-a:toggle-all

Is the problem reproducible with mini.sh?

Fzf-lua configuration

`minimal-example.vim`:

"
" Minimal vim config to reproduce issues without messing with installed plugins.
" Based on https://github.com/hrsh7th/nvim-cmp/blob/main/utils/vimrc.vim
"
" To start vim with this config:
"  vim -u /path/to/minimal-example.vim
"
if has('vim_starting')
  set encoding=utf-8
endif
scriptencoding utf-8

if &compatible
  set nocompatible
endif

let s:plug_dir = expand('/tmp/plugged/vim-plug')
if !filereadable(s:plug_dir .. '/plug.vim')
  execute printf('!curl -fLo %s/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim', s:plug_dir)
end

execute 'set runtimepath+=' . s:plug_dir
call plug#begin(s:plug_dir)
Plug 'ibhagwan/fzf-lua', { 'branch': 'main' }
call plug#end()
PlugInstall | quit

lua << EOF

local actions = require "fzf-lua.actions"
local fzflua = require('fzf-lua')
fzflua.setup({
  'fzf-native',
  winopts = {
    split = "botright new",
    preview = {
      horizontal = 'right:50%',
    },
  },
  actions = {
    files = {
      -- providers that inherit these actions:
      --   files, git_files, git_status, grep, lsp
      --   oldfiles, quickfix, loclist, tags, btags, args
      ["default"]     = actions.file_edit,
      ["ctrl-x"]      = actions.file_split,
      ["ctrl-v"]      = actions.file_vsplit,
      ["alt-q"]       = actions.file_sel_to_qf,
      ["alt-l"]       = actions.file_sel_to_ll,
    },
    buffers = {
      -- providers that inherit these actions:
      --   buffers, tabs, lines, blines
      ["default"]     = actions.buf_edit,
      ["ctrl-x"]      = actions.buf_split,
      ["ctrl-v"]      = actions.buf_vsplit,
    }
  },
  fzf_colors = {
      ['fg']          = { 'fg', 'Normal' },
      ['bg']          = { 'bg', 'Normal' },
      ['hl']          = { 'fg', 'Green' },
      ['fg+']         = { 'fg', 'CursorLine' },
      ['bg+']         = { 'bg', 'CursorLine' },
      ['hl+']         = { 'fg', 'Green' },
      ['info']        = { 'fg', 'Yellow' },
      ['prompt']      = { 'fg', 'Red' },
      ['pointer']     = { 'fg', 'Blue' },
      ['marker']      = { 'fg', 'Blue' },
      ['spinner']     = { 'fg', 'Yellow' },
      ['header']      = { 'fg', 'Blue' },
      ['gutter']      = { 'bg', 'Normal' },
  },
  -- providers
  buffers = {
    filename_only = true,
    winopts = {
      split = "topleft new",
    },
    actions = {
      -- actions inherit from 'actions.buffers'
      -- by supplying a table of functions we're telling
      -- fzf-lua to not close the fzf window
      -- can resume the buffers picker on the same window
      -- eliminating an otherwise unaesthetic win "flash"
      ["ctrl-q"]      = { fn = actions.buf_del, reload = true },
      -- override plugin default mapping
      ["ctrl-x"]      = actions.buf_split,
    }
  },
  files = {
    path_shorten = false,
  },
  git = {
    status = {
      preview_pager = 'delta --width=$FZF_PREVIEW_COLUMNS',
    },
    commits = {
      preview_pager = 'DELTA_FEATURES=+ delta --width=$FZF_PREVIEW_COLUMNS',
    },
    bcommits = {
      preview_pager = 'delta --width=$FZF_PREVIEW_COLUMNS',
      actions = {
        ['ctrl-x'] = actions.git_buf_split,
      }
    },
  },
  grep = {
    path_shorten = true,
    winopts = {
      split = false,
      fullscreen = true,
    },
  },
  highlights = {
    winopts = {
      split = false,
      fullscreen = true,
    },
  },
  lsp = {
    -- use async calls instead of sync + timeout
    async_or_timeout = true,
    symbols = {
      winopts = {
        split = false,
        fullscreen = true,
      },
    },
  },
  oldfiles = {
    cwd_only = true,
    winopts = {
      preview = { hidden = "hidden" },
    },
  },
})

EOF

let mapleader = ','       " Map <leader> to , instead of default \
nmap <leader>t <Cmd>NvimTreeFindFileToggle<CR>
nmap <leader>/ <Cmd>FzfLua live_grep path_shorten=false<CR>

Describe the bug / steps to reproduce

  1. touch {a,b}.txt
  2. nvim -u minimal-example.vim a.txt b.txt
  3. :FzfLua buffers

I get this error:

Error executing vim.schedule lua callback: /tmp/plugged/vim-plug/fzf-lua/lua/fzf-lua/previewer/fzf.lua:271: bad argument #2 to 'format' (number expected, got nil)
stack traceback:
        [C]: in function 'format'
        /tmp/plugged/vim-plug/fzf-lua/lua/fzf-lua/previewer/fzf.lua:271: in function 'fn'
        /tmp/plugged/vim-plug/fzf-lua/lua/fzf-lua/shell.lua:173: in function 'fn'
        /tmp/plugged/vim-plug/fzf-lua/lua/fzf-lua/shell.lua:77: in function </tmp/plugged/vim-plug/fzf-lua/lua/fzf-lua/shell.lua:76>

Sometimes nvim freezes and I have to kill it from another terminal.

Bisected the error to commit 2106d3dd5e44095f6b5c361e1a504398a70048b6.

ibhagwan commented 3 months ago

Ty @mikehaertl, apologize, that’s definitely an error from my latest changes in that commit, I’ll fix it when not AFK.

Can you let me know the output of your :ls (buffer list), it will help me identify which buffer is causing the issue.

Btw, the issue can probably be worked around for the time being with :FzfLua buffers previewer=false

mikehaertl commented 3 months ago
:ls
  1 %a   "a.txt"                        line 1
  2      "b.txt"                        line 0
ibhagwan commented 3 months ago
:ls
  1 %a   "a.txt"                        line 1
  2      "b.txt"                        line 0

Ty @mikehaertl, will be fixed within a few hours.

ibhagwan commented 3 months ago

https://github.com/ibhagwan/fzf-lua/commit/c7288e60b8dde218f3d3b5b16e1baf32ada20ef3

@mikehaertl, should work as expected, ty for the report!

mikehaertl commented 3 months ago

seems to work, thanks!