languages: allow listOf format.type

This commit is contained in:
Ching Pei Yang 2025-08-23 16:04:51 +02:00
commit 70555904a0
No known key found for this signature in database
GPG key ID: B3841364253DC4C8
22 changed files with 265 additions and 357 deletions

View file

@ -59,19 +59,16 @@
};
};
defaultFormat = "gofmt";
defaultFormat = ["gofmt"];
formats = {
gofmt = {
package = pkgs.go;
config.command = "${cfg.format.package}/bin/gofmt";
command = "${pkgs.go}/bin/gofmt";
};
gofumpt = {
package = pkgs.gofumpt;
config.command = getExe cfg.format.package;
command = getExe pkgs.gofumpt;
};
golines = {
package = pkgs.golines;
config.command = "${cfg.format.package}/bin/golines";
command = "${pkgs.golines}/bin/golines";
};
};
@ -113,15 +110,9 @@ in {
type = mkOption {
description = "Go formatter to use";
type = enum (attrNames formats);
type = singleOrListOf (enum (attrNames formats));
default = defaultFormat;
};
package = mkOption {
description = "Go formatter package";
type = package;
default = formats.${cfg.format.type}.package;
};
};
dap = {
@ -163,8 +154,13 @@ in {
(mkIf cfg.format.enable {
vim.formatter.conform-nvim = {
enable = true;
setupOpts.formatters_by_ft.go = [cfg.format.type];
setupOpts.formatters.${cfg.format.type} = formats.${cfg.format.type}.config;
setupOpts.formatters_by_ft.go = cfg.format.type;
setupOpts.formatters =
mapListToAttrs (name: {
inherit name;
value = formats.${name};
})
cfg.format.type;
};
})