|
4 | 4 | lib, |
5 | 5 | ... |
6 | 6 | }: let |
7 | | - inherit (builtins) attrNames; |
| 7 | + inherit (builtins) attrNames warn; |
8 | 8 | inherit (lib.options) mkEnableOption mkOption literalExpression; |
| 9 | + inherit (lib.lists) flatten; |
9 | 10 | inherit (lib.meta) getExe; |
10 | 11 | inherit (lib.modules) mkIf mkMerge; |
11 | 12 | inherit (lib.types) enum package bool; |
|
130 | 131 | package = pkgs.isort; |
131 | 132 | }; |
132 | 133 |
|
133 | | - black-and-isort = { |
134 | | - package = pkgs.writeShellApplication { |
135 | | - name = "black"; |
136 | | - runtimeInputs = [pkgs.black pkgs.isort]; |
137 | | - text = '' |
138 | | - black --quiet - "$@" | isort --profile black - |
139 | | - ''; |
140 | | - }; |
141 | | - }; |
| 134 | + # dummy option for backwards compat |
| 135 | + black-and-isort = {}; |
142 | 136 |
|
143 | 137 | ruff = { |
144 | 138 | package = pkgs.writeShellApplication { |
|
240 | 234 | enable = mkEnableOption "Python formatting" // {default = config.vim.languages.enableFormat;}; |
241 | 235 |
|
242 | 236 | type = mkOption { |
243 | | - type = enum (attrNames formats); |
| 237 | + type = singleOrListOf (enum (attrNames formats)); |
244 | 238 | default = defaultFormat; |
245 | | - description = "Python formatter to use"; |
| 239 | + description = "Python formatters to use"; |
246 | 240 | }; |
247 | 241 |
|
248 | 242 | package = mkOption { |
@@ -316,21 +310,25 @@ in { |
316 | 310 | }) |
317 | 311 |
|
318 | 312 | (mkIf cfg.format.enable { |
319 | | - vim.formatter.conform-nvim = { |
| 313 | + vim.formatter.conform-nvim = let |
| 314 | + names = flatten (map (type: |
| 315 | + if type == "black-and-isort" |
| 316 | + then |
| 317 | + warn '' |
| 318 | + vim.languages.python.format.type: "black-and-isort" is deprecated, |
| 319 | + use `["black" "isort"]` instead. |
| 320 | + '' ["black" "isort"] |
| 321 | + else type) |
| 322 | + cfg.format.type); |
| 323 | + in { |
320 | 324 | enable = true; |
321 | | - # HACK: I'm planning to remove these soon so I just took the easiest way out |
322 | | - setupOpts.formatters_by_ft.python = |
323 | | - if cfg.format.type == "black-and-isort" |
324 | | - then ["black"] |
325 | | - else [cfg.format.type]; |
| 325 | + setupOpts.formatters_by_ft.python = names; |
326 | 326 | setupOpts.formatters = |
327 | | - if (cfg.format.type == "black-and-isort") |
328 | | - then { |
329 | | - black.command = "${cfg.format.package}/bin/black"; |
330 | | - } |
331 | | - else { |
332 | | - ${cfg.format.type}.command = getExe cfg.format.package; |
333 | | - }; |
| 327 | + mapListToAttrs (name: { |
| 328 | + inherit name; |
| 329 | + value = {command = getExe formats.${name}.package;}; |
| 330 | + }) |
| 331 | + names; |
334 | 332 | }; |
335 | 333 | }) |
336 | 334 |
|
|
0 commit comments