From 3b0f5393d9eb3a90ce4e4b0ed8d671a5ac977a46 Mon Sep 17 00:00:00 2001 From: Matthieu Coudron Date: Tue, 30 May 2023 10:44:11 +0200 Subject: [PATCH] neovimUtils.grammarToPlugin: install tree-sitter grammars for neovim without nvim-treesitter nvim-treesitter installs tons of queries that are picked up by neovim even though we sometimes dont want those queries. This makes it possible to install grammars without nvim-treesitter which becomes more and more a repository like nvim-lspconfig, aka a repo that lists others. --- pkgs/applications/editors/neovim/utils.nix | 30 +++++++++++++++++++ .../vim/plugins/nvim-treesitter/overrides.nix | 28 ++--------------- 2 files changed, 32 insertions(+), 26 deletions(-) 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: