Conflicts between treesitter.withAllGrammars and builtin neovim parsers (lua, c, ...)

Hi there,

I’m installing my nvim plugins using nix and access them using lazy.nvim. This hybrid approach works very nicely, but since nvim decided to include some treesitter grammar as part of the default run time path I see some errors, and I can’t figure out how the regular programs.neovim module plugin mechanism avoids them. To get you folks up to speed, this is what I am doing:

I tell lazy.nvim to use a pre-installed (nixpkgs) copy of a plugin using this wrapper. The nvim-treesitter plugin gets told to ensure nothing at all, it’s parsers are available through this runtimepath addition. These three locations work on this piece of nix which installs everything from nixpkgs.

The error I see on affected languages (lua, c, …, not part of my day job luckily) since neovim included these default parsers (since 0.9 I think?) is:

Error detected while processing BufReadPost Autocommands for "*":
Error executing lua callback: ...5-neovim-unwrapped-0.9.2/share/nvim/runtime/filetype.lua:24: Error executing lua: ...5-neovim-unwrapped-0.9.2/share/nvim/runtime/filetype.lua:25: BufReadPost Autocommands for "*"..FileType Autocommands for "*": Vim(append):Error executing lua callback: ...ed-0.9.2/share/nvim/runtime/lua/vim/treesitter/query.lua:259: query: invalid node type at position 3406 for language lua
stack traceback:
	[C]: in function '_ts_parse_query'
	...ed-0.9.2/share/nvim/runtime/lua/vim/treesitter/query.lua:259: in function 'get'
	...2/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:114: in function 'new'
	...nwrapped-0.9.2/share/nvim/runtime/lua/vim/treesitter.lua:61: in function '_create_parser'
	...nwrapped-0.9.2/share/nvim/runtime/lua/vim/treesitter.lua:131: in function 'get_parser'
	...nwrapped-0.9.2/share/nvim/runtime/lua/vim/treesitter.lua:459: in function 'start'
	...ixpkgs/nvim-treesitter/lua/nvim-treesitter/highlight.lua:20: in function 'attach'
	.../nixpkgs/nvim-treesitter/lua/nvim-treesitter/configs.lua:509: in function 'attach_module'
	.../nixpkgs/nvim-treesitter/lua/nvim-treesitter/configs.lua:532: in function 'reattach_module'
	.../nixpkgs/nvim-treesitter/lua/nvim-treesitter/configs.lua:133: in function <.../nixpkgs/nvim-treesitter/lua/nvim-treesitter/configs.lua:132>
	[C]: in function 'nvim_cmd'
	...5-neovim-unwrapped-0.9.2/share/nvim/runtime/filetype.lua:25: in function <...5-neovim-unwrapped-0.9.2/share/nvim/runtime/filetype.lua:24>
	[C]: in function 'nvim_buf_call'
	...5-neovim-unwrapped-0.9.2/share/nvim/runtime/filetype.lua:24: in function <...5-neovim-unwrapped-0.9.2/share/nvim/runtime/filetype.lua:10>
stack traceback:
	[C]: in function 'nvim_cmd'
	...5-neovim-unwrapped-0.9.2/share/nvim/runtime/filetype.lua:25: in function <...5-neovim-unwrapped-0.9.2/share/nvim/runtime/filetype.lua:24>
	[C]: in function 'nvim_buf_call'
	...5-neovim-unwrapped-0.9.2/share/nvim/runtime/filetype.lua:24: in function <...5-neovim-unwrapped-0.9.2/share/nvim/runtime/filetype.lua:10>
stack traceback:
	[C]: in function 'nvim_buf_call'
	...5-neovim-unwrapped-0.9.2/share/nvim/runtime/filetype.lua:24: in function <...5-neovim-unwrapped-0.9.2/share/nvim/runtime/filetype.lua:10>

This is even mentioned in the nvim-treesitter FAQs and can be seen by :echo nvim_get_runtime_file('parser', v:true) which outputs both parser locations. The suggested fix is to delete the external parsers, but I can’t get withAllGrammars to skip the builtins (see the comment on the linked nix file). Any pointers are very much appreciated :slight_smile:

Hey, just wanted to jump in and say I’ve also been experiencing this for a while. I couldn’t find any suggested fixes after a bit of searching.

Try putting treesitter parsers to ~/.config/nvim using this:

    xdg.configFile."nvim/parser".source = "${pkgs.symlinkJoin {
      name = "treesitter-parsers";
      paths = (pkgs.vimPlugins.nvim-treesitter.withPlugins (plugins: with plugins; [
        c
        lua
        query
      ])).dependencies;
    }}/parser";

Since ~/.config/nvim has higher priority than neovim built-in runtime path, the parsers from pkgs.vimPlugins.nvim-treesitter will be used.

2 Likes