diff --git a/pkgs/applications/editors/neovim/utils.nix b/pkgs/applications/editors/neovim/utils.nix index 3911026c7725..038b9cc011ce 100644 --- a/pkgs/applications/editors/neovim/utils.nix +++ b/pkgs/applications/editors/neovim/utils.nix @@ -9,8 +9,11 @@ , python3Packages , writeText , wrapNeovimUnstable +, runCommand }: let + inherit (vimUtils) toVimPlugin; + /* returns everything needed for the caller to wrap its own neovim: - the generated content of the future init.vim - the arguments to wrap neovim with @@ -197,11 +200,38 @@ let inherit (vimUtils) toVimPlugin; inherit lua; }; + + grammarToPlugin = grammar: + let + name = lib.pipe grammar [ + lib.getName + + # added in buildGrammar + (lib.removeSuffix "-grammar") + + # grammars from tree-sitter.builtGrammars + (lib.removePrefix "tree-sitter-") + (lib.replaceStrings [ "-" ] [ "_" ]) + ]; + in + + toVimPlugin (runCommand "vimplugin-treesitter-grammar-${name}" + { + meta = { + platforms = lib.platforms.all; + } // grammar.meta; + } + '' + mkdir -p $out/parser + ln -s ${grammar}/parser $out/parser/${name}.so + ''); + in { inherit makeNeovimConfig; inherit generateProviderRc; inherit legacyWrapper; + inherit grammarToPlugin; inherit buildNeovimPlugin; buildNeovimPluginFrom2Nix = lib.warn "buildNeovimPluginFrom2Nix was renamed to buildNeovimPlugin" buildNeovimPlugin; diff --git a/pkgs/applications/editors/vim/plugins/nvim-treesitter/overrides.nix b/pkgs/applications/editors/vim/plugins/nvim-treesitter/overrides.nix index 4914ff196a5c..566d6e8647cf 100644 --- a/pkgs/applications/editors/vim/plugins/nvim-treesitter/overrides.nix +++ b/pkgs/applications/editors/vim/plugins/nvim-treesitter/overrides.nix @@ -1,8 +1,9 @@ -{ lib, callPackage, tree-sitter, neovim, runCommand }: +{ lib, callPackage, tree-sitter, neovim, neovimUtils, runCommand }: self: super: let + inherit (neovimUtils) grammarToPlugin; generatedGrammars = callPackage ./generated.nix { inherit (tree-sitter) buildGrammar; }; @@ -27,31 +28,6 @@ let }) generatedDerivations; - grammarToPlugin = grammar: - let - name = lib.pipe grammar [ - lib.getName - - # added in buildGrammar - (lib.removeSuffix "-grammar") - - # grammars from tree-sitter.builtGrammars - (lib.removePrefix "tree-sitter-") - (lib.replaceStrings [ "-" ] [ "_" ]) - ]; - in - - runCommand "nvim-treesitter-grammar-${name}" - { - meta = { - platforms = lib.platforms.all; - } // grammar.meta; - } - '' - mkdir -p $out/parser - ln -s ${grammar}/parser $out/parser/${name}.so - ''; - allGrammars = lib.attrValues generatedDerivations; # Usage: