3
0
Fork 0
forked from mirrors/nixpkgs

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.
This commit is contained in:
Matthieu Coudron 2023-05-30 10:44:11 +02:00 committed by Matthieu Coudron
parent 3463e24e1d
commit 3b0f5393d9
2 changed files with 32 additions and 26 deletions

View file

@ -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;

View file

@ -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: