diff --git a/gnu/local.mk b/gnu/local.mk index 5bc8413d2a..fae467e500 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -1978,6 +1978,7 @@ dist_patch_DATA = \ %D%/packages/patches/nheko-0-12-1-fix-rendering-replies.patch \ %D%/packages/patches/nix-dont-build-html-doc.diff \ %D%/packages/patches/nfs4-acl-tools-0.3.7-fixpaths.patch \ + %D%/packages/patches/neovim-tree-sitter-grammar-path.patch \ %D%/packages/patches/network-manager-plugin-ownership.patch \ %D%/packages/patches/network-manager-plugin-path.patch \ %D%/packages/patches/newlib-getentropy.patch \ diff --git a/gnu/packages/patches/neovim-tree-sitter-grammar-path.patch b/gnu/packages/patches/neovim-tree-sitter-grammar-path.patch new file mode 100644 index 0000000000..30d76ad36f --- /dev/null +++ b/gnu/packages/patches/neovim-tree-sitter-grammar-path.patch @@ -0,0 +1,33 @@ +This patch makes neovim look for tree-sitter parsers in the directories +specified by TREE_SITTER_GRAMMAR_PATH. Thereby, making it compatible +with the tree-sitter setup used by other Guix packages. e.g. emacs. + +diff --git a/runtime/lua/vim/treesitter/language.lua b/runtime/lua/vim/treesitter/language.lua +index f70f99421c..480e7bb77a 100644 +--- a/runtime/lua/vim/treesitter/language.lua ++++ b/runtime/lua/vim/treesitter/language.lua +@@ -126,12 +126,19 @@ function M.add(lang, opts) + return nil, string.format('Invalid language name "%s"', lang) + end + +- local fname = 'parser/' .. lang .. '.*' +- local paths = api.nvim_get_runtime_file(fname, false) +- if #paths == 0 then +- return nil, string.format('No parser for language "%s"', lang) ++ local paths = vim.split(os.getenv('TREE_SITTER_GRAMMAR_PATH') or '', ':') ++ for _, elem in ipairs(paths) do ++ local fname = elem .. '/' .. 'libtree-sitter-' .. lang .. '*' ++ local paths = vim.fn.glob(fname, false, true) ++ if #paths > 0 then ++ path = paths[1] ++ break ++ end + end +- path = paths[1] ++ end ++ ++ if path == nil then ++ return nil, string.format('No parser for language "%s"', lang) + end + + local res = loadparser(path, lang, symbol_name) diff --git a/gnu/packages/vim.scm b/gnu/packages/vim.scm index c37131cb7a..08bc2d9c04 100644 --- a/gnu/packages/vim.scm +++ b/gnu/packages/vim.scm @@ -801,7 +801,8 @@ is based on Vim's builtin plugin support.") (file-name (git-file-name name version)) (sha256 (base32 - "1b524vi44gkcsyy8w4jggvprwdsgy0gjprgxpyhh0dmqm47c0c48")))) + "1b524vi44gkcsyy8w4jggvprwdsgy0gjprgxpyhh0dmqm47c0c48")) + (patches (search-patches "neovim-tree-sitter-grammar-path.patch")))) (build-system cmake-build-system) (arguments (list #:tests? #f @@ -852,6 +853,19 @@ is based on Vim's builtin plugin support.") lua5.1-libmpack tree-sitter)) (native-inputs (list pkg-config gettext-minimal gperf)) + (propagated-inputs + ;; bundled tree-sitters, neovim assumes that these are available. + ;; See https://neovim.io/doc/user/treesitter.html#treesitter-parsers + (list tree-sitter-c + tree-sitter-lua + tree-sitter-markdown + tree-sitter-vim + tree-sitter-vimdoc + tree-sitter-query)) + (native-search-paths + (list (search-path-specification + (variable "TREE_SITTER_GRAMMAR_PATH") + (files '("lib/tree-sitter"))))) (home-page "https://neovim.io") (synopsis "Fork of vim focused on extensibility and agility") (description