summary refs log tree commit diff
path: root/pkgs/applications/editors/neovim
diff options
context:
space:
mode:
authorMatthieu Coudron <mcoudron@hotmail.com>2023-05-30 10:44:11 +0200
committerMatthieu Coudron <teto@users.noreply.github.com>2023-06-12 18:36:14 +0200
commit3b0f5393d9eb3a90ce4e4b0ed8d671a5ac977a46 (patch)
tree592410e1fc34a34dfd9d6e32b2c418c2209b4f70 /pkgs/applications/editors/neovim
parent3463e24e1d1df4d9f47c6e74e62864f915010db2 (diff)
downloadnixpkgs-3b0f5393d9eb3a90ce4e4b0ed8d671a5ac977a46.tar
nixpkgs-3b0f5393d9eb3a90ce4e4b0ed8d671a5ac977a46.tar.gz
nixpkgs-3b0f5393d9eb3a90ce4e4b0ed8d671a5ac977a46.tar.bz2
nixpkgs-3b0f5393d9eb3a90ce4e4b0ed8d671a5ac977a46.tar.lz
nixpkgs-3b0f5393d9eb3a90ce4e4b0ed8d671a5ac977a46.tar.xz
nixpkgs-3b0f5393d9eb3a90ce4e4b0ed8d671a5ac977a46.tar.zst
nixpkgs-3b0f5393d9eb3a90ce4e4b0ed8d671a5ac977a46.zip
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.
Diffstat (limited to 'pkgs/applications/editors/neovim')
-rw-r--r--pkgs/applications/editors/neovim/utils.nix30
1 files changed, 30 insertions, 0 deletions
diff --git a/pkgs/applications/editors/neovim/utils.nix b/pkgs/applications/editors/neovim/utils.nix
index 3911026c772..038b9cc011c 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;