plugins/treesitter: cleanup build-grammar deps impl

This commit is contained in:
Matt Sturgeon 2025-04-12 04:34:16 +01:00
parent b2e8409b64
commit 2ecd643311
No known key found for this signature in database
GPG key ID: 4F91844CED1A8299

View file

@ -2,9 +2,17 @@
lib, lib,
helpers, helpers,
config, config,
options,
... ...
}: }:
with lib; with lib;
let
buildGrammarDeps = [
"gcc"
"nodejs"
"tree-sitter"
];
in
lib.nixvim.plugins.mkNeovimPlugin { lib.nixvim.plugins.mkNeovimPlugin {
name = "treesitter"; name = "treesitter";
packPathName = "nvim-treesitter"; packPathName = "nvim-treesitter";
@ -421,7 +429,7 @@ lib.nixvim.plugins.mkNeovimPlugin {
# NOTE: We call setup manually below. # NOTE: We call setup manually below.
callSetup = false; callSetup = false;
extraConfig = cfg: { extraConfig = cfg: opt: {
plugins.treesitter.luaConfig.content = plugins.treesitter.luaConfig.content =
# NOTE: Upstream state that the parser MUST be at the beginning of runtimepath. # NOTE: Upstream state that the parser MUST be at the beginning of runtimepath.
# Otherwise the parsers from Neovim takes precedent, which may be incompatible with some queries. # Otherwise the parsers from Neovim takes precedent, which may be incompatible with some queries.
@ -448,25 +456,21 @@ lib.nixvim.plugins.mkNeovimPlugin {
pkg: pkg.withPlugins (_: cfg.grammarPackages) pkg: pkg.withPlugins (_: cfg.grammarPackages)
); );
dependencies = lib.mkIf (!cfg.nixGrammars) { # These deps are required to build grammars when not using `nixGrammars`:
gcc.enable = lib.mkDefault true; dependencies = lib.mkIf (!cfg.nixGrammars) (
nodejs.enable = lib.mkDefault true; lib.genAttrs buildGrammarDeps (_: {
tree-sitter.enable = lib.mkDefault true; enable = lib.mkDefault true;
}; })
);
warnings = lib.nixvim.mkWarnings "plugins.treesitter" ( warnings = lib.nixvim.mkWarnings "plugins.treesitter" (
lib.map lib.map (packageName: {
(packageName: { when = !cfg.nixGrammars && !config.dependencies.${packageName}.enable;
when = !cfg.nixGrammars && (!config.dependencies.${packageName}.enable); message = ''
message = '' `${packageName}` is required to build grammars as you are not using `${opt.nixGrammars}`.
`${packageName}` is required to build grammars as you are not using `nixGrammars`. You may want to set `${options.dependencies.${packageName}.enable}` to `true`.
You may want to set `dependencies.${packageName}.enable` to `true`. '';
''; }) buildGrammarDeps
})
[
"gcc"
"nodejs"
"tree-sitter"
]
); );
opts = mkIf cfg.folding { opts = mkIf cfg.folding {