plugins/nvim-treesitter: add extraQueries

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

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 = { };