3
0
Fork 0
forked from mirrors/nixpkgs

tree-sitter: Add withPlugins

This commit is contained in:
José Luis Lafuente 2021-03-16 19:39:23 +01:00 committed by Matthieu Coudron
parent a48ea1b0b3
commit f29292db76
2 changed files with 51 additions and 1 deletions

View file

@ -71,6 +71,35 @@ let
in
lib.mapAttrs change grammars;
# Usage:
# pkgs.tree-sitter.withPlugins (p: [ p.tree-sitter-c p.tree-sitter-java ... ])
#
# or for all grammars:
# pkgs.tree-sitter.withPlugins (_: allGrammars)
# which is equivalent to
# pkgs.tree-sitter.withPlugins (p: builtins.attrValues p)
withPlugins = grammarFn:
let
grammars = grammarFn builtGrammars;
in
linkFarm "grammars"
(map
(drv:
let
name = lib.strings.getName drv;
in
{
name =
(lib.strings.removePrefix "tree-sitter-"
(lib.strings.removeSuffix "-grammar" name))
+ stdenv.hostPlatform.extensions.sharedLibrary;
path = "${drv}/parser";
}
)
grammars);
allGrammars = builtins.attrValues builtGrammars;
in
rustPlatform.buildRustPackage {
pname = "tree-sitter";
@ -111,7 +140,7 @@ rustPlatform.buildRustPackage {
updater = {
inherit update-all-grammars;
};
inherit grammars builtGrammars;
inherit grammars builtGrammars withPlugins allGrammars;
tests = {
# make sure all grammars build

View file

@ -50,6 +50,9 @@
, CoreFoundation
, CoreServices
# nvim-treesitter dependencies
, tree-sitter
# sved dependencies
, glib
, gobject-introspection
@ -364,6 +367,24 @@ self: super: {
dependencies = with super; [ popfix ];
});
# Usage:
# pkgs.vimPlugins.nvim-treesitter.withPlugins (p: [ p.tree-sitter-c p.tree-sitter-java ... ])
# or for all grammars:
# pkgs.vimPlugins.nvim-treesitter.withPlugins (_: tree-sitter.allGrammars)
nvim-treesitter = super.nvim-treesitter.overrideAttrs (old: {
passthru.withPlugins =
grammarFn: self.nvim-treesitter.overrideAttrs (_: {
postPatch =
let
grammars = tree-sitter.withPlugins grammarFn;
in
''
rm -r parser
ln -s ${grammars} parser
'';
});
});
onehalf = super.onehalf.overrideAttrs (old: {
configurePhase = "cd vim";
});