ibhagwan / fzf-lua

Improved fzf.vim written in lua
MIT License
2.37k stars 151 forks source link

[previewer/builtin] turn utils.has_ts_parser call into protected call #1469

Closed balazs4 closed 1 month ago

balazs4 commented 1 month ago

I've experienced that recent changes causes the following error if TreeSitter is not activated.

I get this error even on require('fzf-lua').files call:

Error executing vim.schedule lua callback: ...arm64/share/nvim/runtime/lua/vim/treesitter/language.lua:84: lang: expected string, got nil
stack traceback:
        [C]: in function 'error'
        vim/shared.lua: in function 'validate'
        ...arm64/share/nvim/runtime/lua/vim/treesitter/language.lua:84: in function 'has_ts_parser'
        ...e/pack/_/start/fzf-lua/lua/fzf-lua/previewer/builtin.lua:758: in function 'ts_attach'
        ...e/pack/_/start/fzf-lua/lua/fzf-lua/previewer/builtin.lua:825: in function <...e/pack/_/start/fzf-lua/lua/fzf-lua/previewer/builtin.lua:803>
        ...e/pack/_/start/fzf-lua/lua/fzf-lua/previewer/builtin.lua:833: in function 'do_syntax'
        ...e/pack/_/start/fzf-lua/lua/fzf-lua/previewer/builtin.lua:954: in function 'preview_buf_post'
        ...e/pack/_/start/fzf-lua/lua/fzf-lua/previewer/builtin.lua:716: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>
$ nvim --version
NVIM v0.11.0-dev-836+g64847fbdc
Build type: RelWithDebInfo
LuaJIT 2.1.1724512491
Run "nvim -V1 -v" for more info
$ fzf --version
0.55 (devel)

This PR turns the related call (following stacking trace) into protected call.

I've tested it with my own config .config/nvim/init.lua on macOS.

ibhagwan commented 1 month ago

This was just changed in #1464 by @RayGuo-ergou.

ibhagwan commented 1 month ago

I just tried reproducing this on NVIM v0.11.0-dev-881+g865ba42e0 without treesitter enabled with no success.

Is it possible NVIM v0.11.0-dev-836+g64847fbdc doesn’t contain the aforementioned upstream treesitter changes? Can you try with the latest nightly?

RayGuo-ergou commented 1 month ago

Hi @balazs4 try to upgrade your neovim to recent nightly. Should fix your issue.

The reason for my PR was to adopt new breaking change in neovim and yes it will break for some nightly users but I think the point of "nightly" is to expect breaking changes with most advanced features. So I feel this should not be reverted.

RayGuo-ergou commented 1 month ago

Had a second look into upstream change, it seems the 'add' function was only return void(nil in lua?) before the breaking change. Which means loaded is always falsely.

ibhagwan commented 1 month ago

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

Looking at the error it seems that lang is returned nil and then the call to vim.treesitter.start will fail, I simplified the PR by validating lang before calling utils.has_ts_parser, merged manually

RayGuo-ergou commented 1 month ago

Ah that's right sorry did not pay much attention to the error message.

balazs4 commented 1 month ago

@ibhagwan @RayGuo-ergou thanks for quick response here! 🙏

i've just updated both nvim-nightly and fzf-lua (with the merged commit); it works ✅

ps: Thanks for this extension, btw. 💯

ibhagwan commented 1 month ago

Ty @balazs4 for confirming the fix, the PR and your kind words 🥳