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

@ -12,7 +12,7 @@
inherit (lib.generators) mkLuaInline;
inherit (lib.nvim.attrsets) mapListToAttrs;
inherit (lib.nvim.lua) toLuaObject;
inherit (lib.nvim.types) mkGrammarOption diagnostics mkPluginSetupOption singleOrListOf;
inherit (lib.nvim.types) mkGrammarOption diagnostics mkPluginSetupOption deprecatedSingleOrListOf;
inherit (lib.nvim.dag) entryAnywhere entryBefore;
cfg = config.vim.languages.ts;
@ -173,18 +173,18 @@
'';
# TODO: specify packages
defaultFormat = "prettier";
defaultFormat = ["prettier"];
formats = {
prettier = {
package = pkgs.prettier;
command = getExe pkgs.prettier;
};
prettierd = {
package = pkgs.prettierd;
command = getExe pkgs.prettierd;
};
biome = {
package = pkgs.biome;
command = getExe pkgs.biome;
};
};
@ -225,7 +225,7 @@ in {
enable = mkEnableOption "Typescript/Javascript LSP support" // {default = config.vim.lsp.enable;};
servers = mkOption {
type = singleOrListOf (enum (attrNames servers));
type = deprecatedSingleOrListOf "vim.language.ts.lsp.servers" (enum (attrNames servers));
default = defaultServers;
description = "Typescript/Javascript LSP server to use";
};
@ -236,15 +236,9 @@ in {
type = mkOption {
description = "Typescript/Javascript formatter to use";
type = enum (attrNames formats);
type = deprecatedSingleOrListOf "vim.language.ts.format.type" (enum (attrNames formats));
default = defaultFormat;
};
package = mkOption {
description = "Typescript/Javascript formatter package";
type = package;
default = formats.${cfg.format.type}.package;
};
};
extraDiagnostics = {
@ -306,12 +300,15 @@ in {
vim.formatter.conform-nvim = {
enable = true;
setupOpts = {
formatters_by_ft.typescript = [cfg.format.type];
formatters_by_ft.typescript = cfg.format.type;
# .tsx files
formatters_by_ft.typescriptreact = [cfg.format.type];
formatters.${cfg.format.type} = {
command = getExe cfg.format.package;
};
formatters_by_ft.typescriptreact = cfg.format.type;
setupOpts.formatters =
mapListToAttrs (name: {
inherit name;
value = formats.${name};
})
cfg.format.type;
};
};
})