plugins/nvim-treesitter: add extraQueries #3

Merged
pleshevskiy merged 1 commit from tree-sitter-queries into main 2024-11-08 23:45:12 +03:00
Showing only changes of commit 20bf0c7e51 - Show all commits

View file

@ -14,8 +14,34 @@ let
if cfg.grammars == null then cfg.package.withAllGrammars if cfg.grammars == null then cfg.package.withAllGrammars
else cfg.package.withPlugins cfg.grammars; else cfg.package.withPlugins cfg.grammars;
postPatchExtraGrammars = lib.concatLines (lib.flip
lib.mapAttrsToList
cfg.extraGrammars
(k: { src, language, ... }:
''
if [ -d ${src}/queries ]; then
ln -s ${src}/queries queries/${language}
fi
''
)
);
postPatchExtraQueries = lib.concatLines (lib.flatten
(lib.flip lib.mapAttrsToList cfg.extraQueries (
lang:
lib.mapAttrsToList (queryKind: queries:
let file = pkgs.writeText "${lang}-${queryKind}" queries; in
''
mkdir -p queries/${lang}
cat ${file} >> queries/${lang}/${queryKind}.scm
''
)
))
);
finalNvimTreeSitter = finalNvimTreeSitter =
if cfg.extraGrammars == { } then nvimTreeSitterWithBuiltinGrammars if cfg.extraGrammars == { } && cfg.extraQueries == { } then nvimTreeSitterWithBuiltinGrammars
else else
nvimTreeSitterWithBuiltinGrammars.overrideAttrs (oldAttrs: { nvimTreeSitterWithBuiltinGrammars.overrideAttrs (oldAttrs: {
passthru.dependencies = oldAttrs.passthru.dependencies passthru.dependencies = oldAttrs.passthru.dependencies
@ -26,15 +52,9 @@ let
'' ''
)); ));
postPatch = oldAttrs.postPatch + (lib.concatLines postPatch = oldAttrs.postPatch
(lib.flip lib.mapAttrsToList cfg.extraGrammars (k: { src, language, ... }: + postPatchExtraGrammars
'' + postPatchExtraQueries;
if [ -d ${src}/queries ]; then
ln -s ${src}/queries queries/${language}
fi
''
))
);
}); });
in in
{ {
@ -62,6 +82,21 @@ in
default = { }; default = { };
}; };
extraQueries = mkOption {
type = with types; attrsOf (submodule {
options = {
injections = mkOption {
type = str;
default = "";
};
};
});
default = { };
example = {
javascript.injections = ''(comment) @comment'';
};
};
settings = mkOption { settings = mkOption {
type = types.attrs; type = types.attrs;
default = { }; default = { };