git.iko.soy/typeable/nixpkgs
on master help sign in
tree-sitter: Add withPlugins
commitf29292db76356bfbd02dceb2ca795f67b68d2be6 authorJosé Luis Lafuente <jl@lafuente.me> dateTue 16 Mar 2021, 19:39 (6 years ago) parenta48ea1b
2 files changed+51−1
pkgs/development/tools/parsing/tree-sitter/default.nix+30−1 pkgs/misc/vim-plugins/overrides.nix+21
pkgs/development/tools/parsing/tree-sitter/default.nix+30−1
@@ -71,6 +71,35 @@ let
7171 in
7272 lib.mapAttrs change grammars;
7373
74+ # Usage:
75+ # pkgs.tree-sitter.withPlugins (p: [ p.tree-sitter-c p.tree-sitter-java ... ])
76+ #
77+ # or for all grammars:
78+ # pkgs.tree-sitter.withPlugins (_: allGrammars)
79+ # which is equivalent to
80+ # pkgs.tree-sitter.withPlugins (p: builtins.attrValues p)
81+ withPlugins = grammarFn:
82+ let
83+ grammars = grammarFn builtGrammars;
84+ in
85+ linkFarm "grammars"
86+ (map
87+ (drv:
88+ let
89+ name = lib.strings.getName drv;
90+ in
91+ {
92+ name =
93+ (lib.strings.removePrefix "tree-sitter-"
94+ (lib.strings.removeSuffix "-grammar" name))
95+ + stdenv.hostPlatform.extensions.sharedLibrary;
96+ path = "${drv}/parser";
97+ }
98+ )
99+ grammars);
100+
101+ allGrammars = builtins.attrValues builtGrammars;
102+
74103in
75104rustPlatform.buildRustPackage {
76105 pname = "tree-sitter";
@@ -111,7 +140,7 @@ rustPlatform.buildRustPackage {
111140 updater = {
112141 inherit update-all-grammars;
113142 };
114− inherit grammars builtGrammars;
143+ inherit grammars builtGrammars withPlugins allGrammars;
115144
116145 tests = {
117146 # make sure all grammars build
pkgs/misc/vim-plugins/overrides.nix+21
@@ -50,6 +50,9 @@
5050, CoreFoundation
5151, CoreServices
5252
53+# nvim-treesitter dependencies
54+, tree-sitter
55+
5356 # sved dependencies
5457, glib
5558, gobject-introspection
@@ -364,6 +367,24 @@ self: super: {
364367 dependencies = with super; [ popfix ];
365368 });
366369
370+ # Usage:
371+ # pkgs.vimPlugins.nvim-treesitter.withPlugins (p: [ p.tree-sitter-c p.tree-sitter-java ... ])
372+ # or for all grammars:
373+ # pkgs.vimPlugins.nvim-treesitter.withPlugins (_: tree-sitter.allGrammars)
374+ nvim-treesitter = super.nvim-treesitter.overrideAttrs (old: {
375+ passthru.withPlugins =
376+ grammarFn: self.nvim-treesitter.overrideAttrs (_: {
377+ postPatch =
378+ let
379+ grammars = tree-sitter.withPlugins grammarFn;
380+ in
381+ ''
382+ rm -r parser
383+ ln -s ${grammars} parser
384+ '';
385+ });
386+ });
387+
367388 onehalf = super.onehalf.overrideAttrs (old: {
368389 configurePhase = "cd vim";
369390 });