Nvim-treesitter and externally-managed parsers?

The AUR contains a large number of pre-packaged Tree Sitter parsers.

Is there any way to use these with nvim-treesitter? Or is the only option to install them with :TSInstall?

You can modify the install_info table of a language to set a different path. See Adding parsers. One possible problem though is knowing whether the parser needs additional files (usually a scanner.c file).

I’d try writing something like the following (I haven’t actually run it):

local parser_config = require "nvim-treesitter.parsers".get_parser_configs()

for lang, files in pairs {
  zimbu = { 'src/parser.c' },
  julia = { 'src/parser.c', 'src/scanner.c' },
} do
  parser_config[lang] = {
    url = "/path/to/aur/packages/grammars/tree-sitter-" .. lang,
    files = files
  }
end

Does this work if the parser is already compiled? Or does it need to include the raw “grammar” information as well?

I believe it only needs to compile the parser. tree-sitter grammar repos usually have the generated parser.c files included so downstream doesn’t need tree-sitter to generate them (only a C compiler to create the dynamic library loaded by nvim).

I checked a couple of the grammars in the AUR and they seem pretty outdated. Since the AUR does the same as nvim-treesitter —pointing at the git repo— is there any reason in particular to use AUR instead of nvim-treesitter directly? If the parser version and the queries don’t coincide you’ll probably get an error.

I have configured mine as follows:

local parser_config = require "nvim-treesitter.parsers".get_parser_configs()
parser_config.oberon07 = {
  install_info = {
    url = "~/workspace/treesitter/grammars/src/tree-sitter-oberon-07", -- local path or git repo
    files = {"src/parser.c"}, -- note that some parsers also require src/scanner.c or src/scanner.cc
    -- optional entries:
    branch = "dev", -- default branch in case of git repo if different from master
    generate_requires_npm = false, -- if stand-alone parser without npm dependencies
    requires_generate_from_grammar = false, -- if folder contains pre-generated src/parser.c
  },
  filetype = "Mod,obn,ob7,o07,O07,O7,Ob07,Ob7", -- if filetype does not match the parser name
}

You can provide the urls of the AUR grammars you wouldl iike to install. Once you configure this, then you can run the TSInstall. The nvim-treesitter repo has more information on how to set this up.

I hope this helps and please do share your results.

Fidel H Viegas