languages/formatters: allow multiple formatters (#1103)

* language/python: allow multiple formatters

* package: add prettier-plugin-astro

* language/astro: fix prettier, remove prettierd

* package: add prettier-plugin-svelte

* language/svelte: fix prettier, remove prettierd

* languages: allow listOf format.type

* deprecations: add warnings for removed format options

* ruby: remove unused variable

* nix: fix outdated references to format.package

* docs: update release note

* treewide: warn deprecation in singleOrListOf

* conform: add definitions for setupOpts.formatters
This commit is contained in:
Ching Pei Yang 2025-11-16 19:49:21 +01:00 committed by GitHub
commit d5da1a14c3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
47 changed files with 641 additions and 488 deletions

View file

@ -8,8 +8,8 @@
inherit (lib.options) mkEnableOption mkOption;
inherit (lib.meta) getExe';
inherit (lib.modules) mkIf mkMerge;
inherit (lib.types) enum package;
inherit (lib.nvim.types) mkGrammarOption singleOrListOf;
inherit (lib.types) enum;
inherit (lib.nvim.types) mkGrammarOption deprecatedSingleOrListOf;
inherit (lib.generators) mkLuaInline;
inherit (lib.nvim.attrsets) mapListToAttrs;
@ -37,13 +37,10 @@
};
};
defaultFormat = "nimpretty";
defaultFormat = ["nimpretty"];
formats = {
nimpretty = {
package = pkgs.nim;
config = {
command = "${cfg.format.package}/bin/nimpretty";
};
command = "${pkgs.nim}/bin/nimpretty";
};
};
in {
@ -59,7 +56,7 @@ in {
enable = mkEnableOption "Nim LSP support" // {default = config.vim.lsp.enable;};
servers = mkOption {
type = singleOrListOf (enum (attrNames servers));
type = deprecatedSingleOrListOf "vim.language.nim.lsp.servers" (enum (attrNames servers));
default = defaultServers;
description = "Nim LSP server to use";
};
@ -68,16 +65,10 @@ in {
format = {
enable = mkEnableOption "Nim formatting" // {default = config.vim.languages.enableFormat;};
type = mkOption {
type = enum (attrNames formats);
type = deprecatedSingleOrListOf "vim.language.nim.format.type" (enum (attrNames formats));
default = defaultFormat;
description = "Nim formatter to use";
};
package = mkOption {
type = package;
default = formats.${cfg.format.type}.package;
description = "Nim formatter package";
};
};
};
@ -108,8 +99,15 @@ in {
(mkIf cfg.format.enable {
vim.formatter.conform-nvim = {
enable = true;
setupOpts.formatters_by_ft.nim = [cfg.format.type];
setupOpts.formatters.${cfg.format.type} = formats.${cfg.format.type}.config;
setupOpts = {
formatters_by_ft.nim = cfg.format.type;
formatters =
mapListToAttrs (name: {
inherit name;
value = formats.${name};
})
cfg.format.type;
};
};
})
]);