HiPhish / rainbow-delimiters.nvim

Rainbow delimiters for Neovim with Tree-sitter
https://gitlab.com/HiPhish/rainbow-delimiters.nvim
Apache License 2.0
465 stars 34 forks source link

[Bug]: Error when starting nvim #73

Closed jczhang02 closed 4 months ago

jczhang02 commented 6 months ago

Neovim version

0.9.4

Language affected

All filetype

Query

No response

Strategy

No response

Description

Error detected while processing BufReadPost Autocommands for "*":
Error executing lua callback: /usr/share/nvim/runtime/filetype.lua:24: Error executing lua: /usr/share/nvim/runtime/filetype.lua:25: B
ufReadPost Autocommands for "*"..FileType Autocommands for "tex"..FileType Autocommands for "*": Vim(append):Error executing lua callb
ack: ...y/rainbow-delimiters.nvim/lua/rainbow-delimiters/lib.lua:183: Cannot convert given lua type
stack traceback:
        [C]: in function 'nvim_buf_call'
        ...y/rainbow-delimiters.nvim/lua/rainbow-delimiters/lib.lua:183: in function 'attach'
        ...zy/rainbow-delimiters.nvim/plugin/rainbow-delimiters.lua:63: in function <...zy/rainbow-delimiters.nvim/plugin/rainbow-deli
miters.lua:59>
        [C]: in function 'nvim_exec_autocmds'
        ...nvim/site/lazy/lazy.nvim/lua/lazy/core/handler/event.lua:157: in function <...nvim/site/lazy/lazy.nvim/lua/lazy/core/handle
r/event.lua:156>
        [C]: in function 'xpcall'
        ...al/share/nvim/site/lazy/lazy.nvim/lua/lazy/core/util.lua:113: in function 'try'
        ...nvim/site/lazy/lazy.nvim/lua/lazy/core/handler/event.lua:156: in function 'trigger'
        ...nvim/site/lazy/lazy.nvim/lua/lazy/core/handler/event.lua:87: in function <...nvim/site/lazy/lazy.nvim/lua/lazy/core/handler
/event.lua:72>
        [C]: in function 'nvim_cmd'
        /usr/share/nvim/runtime/filetype.lua:25: in function </usr/share/nvim/runtime/filetype.lua:24>
        [C]: in function 'nvim_buf_call'
        /usr/share/nvim/runtime/filetype.lua:24: in function </usr/share/nvim/runtime/filetype.lua:10>
stack traceback:
        [C]: in function 'nvim_cmd'
        /usr/share/nvim/runtime/filetype.lua:25: in function </usr/share/nvim/runtime/filetype.lua:24>
        [C]: in function 'nvim_buf_call'
        /usr/share/nvim/runtime/filetype.lua:24: in function </usr/share/nvim/runtime/filetype.lua:10>
stack traceback:
        [C]: in function 'nvim_buf_call'
        /usr/share/nvim/runtime/filetype.lua:24: in function </usr/share/nvim/runtime/filetype.lua:10>
Error detected while processing BufEnter Autocommands for "*":
Error executing lua callback: ...vim-treesitter-context/lua/treesitter-context/render.lua:94: BufEnter Autocommands for "*"..FileType
Autocommands for "*": Vim(append):Error executing lua callback: ...y/rainbow-delimiters.nvim/lua/rainbow-delimiters/lib.lua:183: Canno
t convert given lua type
stack traceback:
        [C]: in function 'nvim_buf_call'
        ...y/rainbow-delimiters.nvim/lua/rainbow-delimiters/lib.lua:183: in function 'attach'
        ...zy/rainbow-delimiters.nvim/plugin/rainbow-delimiters.lua:63: in function <...zy/rainbow-delimiters.nvim/plugin/rainbow-deli
miters.lua:59>
        [C]: in function '__newindex'
        ...vim-treesitter-context/lua/treesitter-context/render.lua:94: in function 'copy_option'
        ...vim-treesitter-context/lua/treesitter-context/render.lua:122: in function 'highlight_contexts'
        ...vim-treesitter-context/lua/treesitter-context/render.lua:366: in function 'open'
        .../lazy/nvim-treesitter-context/lua/treesitter-context.lua:50: in function 'open'
        .../lazy/nvim-treesitter-context/lua/treesitter-context.lua:111: in function 'f'
        .../lazy/nvim-treesitter-context/lua/treesitter-context.lua:27: in function <.../lazy/nvim-treesitter-context/lua/treesitter-c
ontext.lua:21>
stack traceback:
        [C]: in function '__newindex'
        ...vim-treesitter-context/lua/treesitter-context/render.lua:94: in function 'copy_option'
        ...vim-treesitter-context/lua/treesitter-context/render.lua:122: in function 'highlight_contexts'
        ...vim-treesitter-context/lua/treesitter-context/render.lua:366: in function 'open'
        .../lazy/nvim-treesitter-context/lua/treesitter-context.lua:50: in function 'open'
        .../lazy/nvim-treesitter-context/lua/treesitter-context.lua:111: in function 'f'
        .../lazy/nvim-treesitter-context/lua/treesitter-context.lua:27: in function <.../lazy/nvim-treesitter-context/lua/treesitter-c
ontext.lua:21>
jczhang02 commented 6 months ago

Using gentoo and compile neovim with USE flags LUA_SINGLE_TARGET="luajit

Danielkonge commented 6 months ago

Based on the error it seems that this issue is caused by the nvim_buf_call added to strategy in the last commit, so for now you can probably go back one commits to get around this problem.

I can reproduce the error by setting up the (default) strategy via a function instead of setting it up immediately.

An easy fix for now is to not use nvim_buf_call for strategy (like it was before).

@HiPhish: If you switch to a setup where the functions can accept an optional bufnr, you should probably double check setting up the strategy via a function, since it has a different behavior in the current version compared to query and priority (both of those work fine with functions for me). I haven't really looked into this, but I can't immediately tell what causes this difference.

HiPhish commented 6 months ago

This is really weird because it works for the query. I can confirm that it is broken for strategies though, but only if using nvim_buf_call. I will switch to a function that uses an optional bufnr argument. The error is really weird, I don't understand why it is happening. It looks like returning a table that has function values is where things break. Here is a minimal example which replicates the error:

vim.api.nvim_buf_call(0, function() return {a = function() return 'x' end} end)

@jczhang02 Pleas revert one commit back for the time being. I will fix this shortly.

Danielkonge commented 6 months ago

This is really weird because it works for the query. I can confirm that it is broken for strategies though, but only if using nvim_buf_call. I will switch to a function that uses an optional bufnr argument. The error is really weird, I don't understand why it is happening. It looks like returning a table that has function values is where things break.

Apparently this is a known limitation (that nvim_buf_call cannot contain functions in the return value), since quote: "nvim_buf_call is within the general Nvim API which adheres to msgpack and thus cannot return function values."

See https://github.com/neovim/neovim/issues/26531#issuecomment-1852179283.

HiPhish commented 6 months ago

Please try the current master branch now, it should be fixed. The configuration function can now take the current buffer number as an argument if you want to.

Danielkonge commented 6 months ago

Please try the current master branch now, it should be fixed. The configuration function can now take the current buffer number as an argument if you want to.

It works as I would expect (and LuaLS doesn't even complain about functions of the form function() return ... end which I thought it would with the given type annotations).

I have one note/question: In lib.lua line 71, we have ---@param bufnr integer? Use this buffer as the current buffer, but can bufnr ever be nil? By the type annotations of the query, we expect a function that takes a non-nil bufnr.

HiPhish commented 6 months ago

You are right, the question mark was an oversight. I have corrected it now.

HiPhish commented 4 months ago

Closing this as done.