Skip to content

Commit 4c2ce5e

Browse files
committed
languages: allow listOf format.type
1 parent 266f5bc commit 4c2ce5e

File tree

23 files changed

+314
-349
lines changed

23 files changed

+314
-349
lines changed

modules/plugins/languages/astro.nix

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,21 @@ in {
139139
cfg.lsp.servers;
140140
})
141141

142+
(mkIf cfg.format.enable {
143+
vim.formatter.conform-nvim = {
144+
enable = true;
145+
setupOpts = {
146+
formatters_by_ft.astro = cfg.format.type;
147+
formatters =
148+
mapListToAttrs (name: {
149+
inherit name;
150+
value = formats.${name};
151+
})
152+
cfg.format.type;
153+
};
154+
};
155+
})
156+
142157
(mkIf cfg.extraDiagnostics.enable {
143158
vim.diagnostics.nvim-lint = {
144159
enable = true;

modules/plugins/languages/bash.nix

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
inherit (lib.options) mkOption mkEnableOption;
99
inherit (lib.meta) getExe;
1010
inherit (lib.modules) mkIf mkMerge;
11-
inherit (lib.types) enum package bool;
11+
inherit (lib.types) enum bool;
1212
inherit (lib.generators) mkLuaInline;
1313
inherit (lib.nvim.types) diagnostics mkGrammarOption singleOrListOf;
1414
inherit (lib.nvim.attrsets) mapListToAttrs;
@@ -30,10 +30,10 @@
3030
};
3131
};
3232

33-
defaultFormat = "shfmt";
33+
defaultFormat = ["shfmt"];
3434
formats = {
3535
shfmt = {
36-
package = pkgs.shfmt;
36+
command = getExe pkgs.shfmt;
3737
};
3838
};
3939

@@ -68,16 +68,10 @@ in {
6868
description = "Enable Bash formatting";
6969
};
7070
type = mkOption {
71-
type = enum (attrNames formats);
71+
type = singleOrListOf (enum (attrNames formats));
7272
default = defaultFormat;
7373
description = "Bash formatter to use";
7474
};
75-
76-
package = mkOption {
77-
type = package;
78-
default = formats.${cfg.format.type}.package;
79-
description = "Bash formatter package";
80-
};
8175
};
8276

8377
extraDiagnostics = {
@@ -108,9 +102,14 @@ in {
108102
(mkIf cfg.format.enable {
109103
vim.formatter.conform-nvim = {
110104
enable = true;
111-
setupOpts.formatters_by_ft.sh = [cfg.format.type];
112-
setupOpts.formatters.${cfg.format.type} = {
113-
command = getExe cfg.format.package;
105+
setupOpts = {
106+
formatters_by_ft.sh = cfg.format.type;
107+
formatters =
108+
mapListToAttrs (name: {
109+
inherit name;
110+
value = formats.${name};
111+
})
112+
cfg.format.type;
114113
};
115114
};
116115
})

modules/plugins/languages/clojure.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
inherit (lib.options) mkEnableOption mkOption;
99
inherit (lib.modules) mkIf mkMerge;
1010
inherit (lib.meta) getExe;
11-
inherit (lib.types) enum listOf package;
11+
inherit (lib.types) enum listOf;
1212
inherit (lib.nvim.types) mkGrammarOption;
1313
inherit (lib.nvim.attrsets) mapListToAttrs;
1414

modules/plugins/languages/css.nix

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
inherit (lib.options) mkEnableOption mkOption;
99
inherit (lib.meta) getExe;
1010
inherit (lib.modules) mkIf mkMerge;
11-
inherit (lib.types) enum package;
11+
inherit (lib.types) enum;
1212
inherit (lib.nvim.types) mkGrammarOption singleOrListOf;
1313
inherit (lib.nvim.attrsets) mapListToAttrs;
1414

@@ -30,34 +30,18 @@
3030
};
3131
};
3232

33-
defaultFormat = "prettier";
33+
defaultFormat = ["prettier"];
3434
formats = {
3535
prettier = {
36-
package = pkgs.prettier;
36+
command = getExe pkgs.prettier;
3737
};
3838

3939
prettierd = {
40-
package = pkgs.prettierd;
41-
nullConfig = ''
42-
table.insert(
43-
ls_sources,
44-
null_ls.builtins.formatting.prettier.with({
45-
command = "${cfg.format.package}/bin/prettierd",
46-
})
47-
)
48-
'';
40+
command = getExe pkgs.prettierd;
4941
};
5042

5143
biome = {
52-
package = pkgs.biome;
53-
nullConfig = ''
54-
table.insert(
55-
ls_sources,
56-
null_ls.builtins.formatting.biome.with({
57-
command = "${cfg.format.package}/bin/biome",
58-
})
59-
)
60-
'';
44+
command = getExe pkgs.biome;
6145
};
6246
};
6347
in {
@@ -85,15 +69,9 @@ in {
8569

8670
type = mkOption {
8771
description = "CSS formatter to use";
88-
type = enum (attrNames formats);
72+
type = singleOrListOf (enum (attrNames formats));
8973
default = defaultFormat;
9074
};
91-
92-
package = mkOption {
93-
description = "CSS formatter package";
94-
type = package;
95-
default = formats.${cfg.format.type}.package;
96-
};
9775
};
9876
};
9977

@@ -115,9 +93,14 @@ in {
11593
(mkIf cfg.format.enable {
11694
vim.formatter.conform-nvim = {
11795
enable = true;
118-
setupOpts.formatters_by_ft.css = [cfg.format.type];
119-
setupOpts.formatters.${cfg.format.type} = {
120-
command = getExe cfg.format.package;
96+
setupOpts = {
97+
formatters_by_ft.css = cfg.format.type;
98+
formatters =
99+
mapListToAttrs (name: {
100+
inherit name;
101+
value = formats.${name};
102+
})
103+
cfg.format.type;
121104
};
122105
};
123106
})

modules/plugins/languages/elixir.nix

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
inherit (lib.options) mkEnableOption mkOption;
99
inherit (lib.modules) mkIf mkMerge;
1010
inherit (lib.meta) getExe;
11-
inherit (lib.types) enum package;
11+
inherit (lib.types) enum;
1212
inherit (lib.generators) mkLuaInline;
1313
inherit (lib.nvim.types) mkGrammarOption singleOrListOf;
1414
inherit (lib.nvim.dag) entryAnywhere;
@@ -40,13 +40,10 @@
4040
};
4141
};
4242

43-
defaultFormat = "mix";
43+
defaultFormat = ["mix"];
4444
formats = {
4545
mix = {
46-
package = pkgs.elixir;
47-
config = {
48-
command = "${cfg.format.package}/bin/mix";
49-
};
46+
command = "${pkgs.elixir}/bin/mix";
5047
};
5148
};
5249
in {
@@ -73,16 +70,10 @@ in {
7370
enable = mkEnableOption "Elixir formatting" // {default = config.vim.languages.enableFormat;};
7471

7572
type = mkOption {
76-
type = enum (attrNames formats);
73+
type = singleOrListOf (enum (attrNames formats));
7774
default = defaultFormat;
7875
description = "Elixir formatter to use";
7976
};
80-
81-
package = mkOption {
82-
type = package;
83-
default = formats.${cfg.format.type}.package;
84-
description = "Elixir formatter package";
85-
};
8677
};
8778

8879
elixir-tools = {
@@ -112,9 +103,15 @@ in {
112103
(mkIf cfg.format.enable {
113104
vim.formatter.conform-nvim = {
114105
enable = true;
115-
setupOpts.formatters_by_ft.elixir = [cfg.format.type];
116-
setupOpts.formatters.${cfg.format.type} =
117-
formats.${cfg.format.type}.config;
106+
setupOpts = {
107+
formatters_by_ft.elixir = cfg.format.type;
108+
formatters =
109+
mapListToAttrs (name: {
110+
inherit name;
111+
value = formats.${name};
112+
})
113+
cfg.format.type;
114+
};
118115
};
119116
})
120117

modules/plugins/languages/fsharp.nix

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
}: let
77
inherit (builtins) attrNames;
88
inherit (lib.options) mkEnableOption mkOption;
9-
inherit (lib.types) package enum;
9+
inherit (lib.types) enum;
1010
inherit (lib.meta) getExe;
1111
inherit (lib.modules) mkIf mkMerge;
1212
inherit (lib.generators) mkLuaInline;
@@ -51,10 +51,10 @@
5151
};
5252
};
5353

54-
defaultFormat = "fantomas";
54+
defaultFormat = ["fantomas"];
5555
formats = {
5656
fantomas = {
57-
package = pkgs.fantomas;
57+
command = getExe pkgs.fantomas;
5858
};
5959
};
6060

@@ -81,16 +81,10 @@ in {
8181
enable = mkEnableOption "F# formatting" // {default = config.vim.languages.enableFormat;};
8282

8383
type = mkOption {
84-
type = enum (attrNames formats);
84+
type = singleOrListOf (enum (attrNames formats));
8585
default = defaultFormat;
8686
description = "F# formatter to use";
8787
};
88-
89-
package = mkOption {
90-
type = package;
91-
default = formats.${cfg.format.type}.package;
92-
description = "F# formatter package";
93-
};
9488
};
9589
};
9690
};
@@ -113,9 +107,14 @@ in {
113107
(mkIf cfg.format.enable {
114108
vim.formatter.conform-nvim = {
115109
enable = true;
116-
setupOpts.formatters_by_ft.fsharp = [cfg.format.type];
117-
setupOpts.formatters.${cfg.format.type} = {
118-
command = getExe cfg.format.package;
110+
setupOpts = {
111+
formatters_by_ft.fsharp = cfg.format.type;
112+
formatters =
113+
mapListToAttrs (name: {
114+
inherit name;
115+
value = formats.${name};
116+
})
117+
cfg.format.type;
119118
};
120119
};
121120
})

modules/plugins/languages/go.nix

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,16 @@
5959
};
6060
};
6161

62-
defaultFormat = "gofmt";
62+
defaultFormat = ["gofmt"];
6363
formats = {
6464
gofmt = {
65-
package = pkgs.go;
66-
config.command = "${cfg.format.package}/bin/gofmt";
65+
command = "${pkgs.go}/bin/gofmt";
6766
};
6867
gofumpt = {
69-
package = pkgs.gofumpt;
70-
config.command = getExe cfg.format.package;
68+
command = getExe pkgs.gofumpt;
7169
};
7270
golines = {
73-
package = pkgs.golines;
74-
config.command = "${cfg.format.package}/bin/golines";
71+
command = "${pkgs.golines}/bin/golines";
7572
};
7673
};
7774

@@ -113,15 +110,9 @@ in {
113110

114111
type = mkOption {
115112
description = "Go formatter to use";
116-
type = enum (attrNames formats);
113+
type = singleOrListOf (enum (attrNames formats));
117114
default = defaultFormat;
118115
};
119-
120-
package = mkOption {
121-
description = "Go formatter package";
122-
type = package;
123-
default = formats.${cfg.format.type}.package;
124-
};
125116
};
126117

127118
dap = {
@@ -163,8 +154,15 @@ in {
163154
(mkIf cfg.format.enable {
164155
vim.formatter.conform-nvim = {
165156
enable = true;
166-
setupOpts.formatters_by_ft.go = [cfg.format.type];
167-
setupOpts.formatters.${cfg.format.type} = formats.${cfg.format.type}.config;
157+
setupOpts = {
158+
formatters_by_ft.go = cfg.format.type;
159+
formatters =
160+
mapListToAttrs (name: {
161+
inherit name;
162+
value = formats.${name};
163+
})
164+
cfg.format.type;
165+
};
168166
};
169167
})
170168

0 commit comments

Comments
 (0)