guix-channel

A channel for the Guix package manager

git clone https://git.8pit.net/guix-channel.git

 1This patch makes neovim look for tree-sitter parsers in the directories
 2specified by TREE_SITTER_GRAMMAR_PATH.  Thereby, making it compatible
 3with the tree-sitter setup used by other Guix packages. e.g. emacs.
 4
 5diff --git a/runtime/lua/vim/treesitter/language.lua b/runtime/lua/vim/treesitter/language.lua
 6index f70f99421c..cd424a510f 100644
 7--- a/runtime/lua/vim/treesitter/language.lua
 8+++ b/runtime/lua/vim/treesitter/language.lua
 9@@ -126,15 +126,18 @@ function M.add(lang, opts)
10       return nil, string.format('Invalid language name "%s"', lang)
11     end
12 
13-    local fname = 'parser/' .. lang .. '.*'
14-    local paths = api.nvim_get_runtime_file(fname, false)
15-    if #paths == 0 then
16-      return nil, string.format('No parser for language "%s"', lang)
17+    local paths = vim.split(os.getenv('TREE_SITTER_GRAMMAR_PATH') or '', ':')
18+    for _, elem in ipairs(paths) do
19+      local fname = elem .. '/' .. 'libtree-sitter-' .. lang .. '*'
20+      local paths = vim.fn.glob(fname, false, true)
21+      if #paths > 0 then
22+        path = paths[1]
23+        break
24+      end
25     end
26-    path = paths[1]
27   end
28 
29-  local res = loadparser(path, lang, symbol_name)
30+  local res = loadparser(path or '', lang, symbol_name)
31   return res,
32     res == nil and string.format('Cannot load parser %s for language "%s"', path, lang) or nil
33 end