plugins/nvim-treesitter: add extraQueries

This commit is contained in:
Dmitriy Pleshevskiy 2024-11-08 18:03:08 +03:00
parent 328ed67299
commit ce62376882
Signed by: pleshevskiy
GPG key ID: 17041163DA10A9A2

View file

@ -14,8 +14,33 @@ let
if cfg.grammars == null then cfg.package.withAllGrammars
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:
''
mkdir -p queries/${lang}
echo "${queries}" >> queries/${lang}/${queryKind}.scm
''
)
))
);
finalNvimTreeSitter =
if cfg.extraGrammars == { } then nvimTreeSitterWithBuiltinGrammars
if cfg.extraGrammars == { } && cfg.extraQueries == { } then nvimTreeSitterWithBuiltinGrammars
else
nvimTreeSitterWithBuiltinGrammars.overrideAttrs (oldAttrs: {
passthru.dependencies = oldAttrs.passthru.dependencies
@ -26,15 +51,9 @@ let
''
));
postPatch = oldAttrs.postPatch + (lib.concatLines
(lib.flip lib.mapAttrsToList cfg.extraGrammars (k: { src, language, ... }:
''
if [ -d ${src}/queries ]; then
ln -s ${src}/queries queries/${language}
fi
''
))
);
postPatch = oldAttrs.postPatch
+ postPatchExtraGrammars
+ postPatchExtraQueries;
});
in
{
@ -62,6 +81,21 @@ in
default = { };
};
extraQueries = mkOption {
type = with types; attrsOf (submodule {
options = {
injections = mkOption {
type = either str (listOf str);
default = [ ];
};
};
});
default = { };
example = {
javascript.injections = ''(comment) @comment'';
};
};
settings = mkOption {
type = types.attrs;
default = { };