language/astro: fix prettier, remove prettierd

This commit is contained in:
Ching Pei Yang 2025-08-23 15:17:12 +02:00
commit 6b334ad28f
No known key found for this signature in database
GPG key ID: B3841364253DC4C8

View file

@ -1,4 +1,5 @@
{
self,
config,
pkgs,
lib,
@ -8,7 +9,7 @@
inherit (lib.options) mkEnableOption mkOption;
inherit (lib.modules) mkIf mkMerge;
inherit (lib.meta) getExe;
inherit (lib.types) enum package;
inherit (lib.types) enum coercedTo;
inherit (lib.nvim.attrsets) mapListToAttrs;
inherit (lib.nvim.types) mkGrammarOption diagnostics singleOrListOf;
inherit (lib.generators) mkLuaInline;
@ -40,23 +41,21 @@
};
};
# TODO: specify packages
defaultFormat = "prettier";
formats = {
defaultFormat = ["prettier"];
formats = let
parser = "${self.packages.${pkgs.stdenv.system}.prettier-plugin-astro}/index.js";
in {
prettier = {
package = pkgs.prettier;
};
prettierd = {
package = pkgs.prettierd;
command = getExe pkgs.nodePackages.prettier;
options.ft_parsers.astro = "astro";
prepend_args = ["--plugin=${parser}"];
};
biome = {
package = pkgs.biome;
command = getExe pkgs.biome;
};
};
# TODO: specify packages
defaultDiagnosticsProvider = ["eslint_d"];
diagnosticsProviders = {
eslint_d = let
@ -76,6 +75,15 @@
};
};
};
formatType =
singleOrListOf
"vim.languages.astro.format.type"
(coercedTo (enum ["prettierd"]) (_:
lib.warn
"vim.languages.astro.format.type: prettierd is deprecated, use prettier instead"
"prettier")
(enum (attrNames formats)));
in {
options.vim.languages.astro = {
enable = mkEnableOption "Astro language support";
@ -89,7 +97,7 @@ in {
lsp = {
enable = mkEnableOption "Astro LSP support" // {default = config.vim.lsp.enable;};
servers = mkOption {
type = singleOrListOf (enum (attrNames servers));
type = singleOrListOf "vim.languages.astro.lsp.servers" (enum (attrNames servers));
default = defaultServers;
description = "Astro LSP server to use";
};
@ -99,16 +107,10 @@ in {
enable = mkEnableOption "Astro formatting" // {default = config.vim.languages.enableFormat;};
type = mkOption {
type = enum (attrNames formats);
type = formatType;
default = defaultFormat;
description = "Astro formatter to use";
};
package = mkOption {
type = package;
default = formats.${cfg.format.type}.package;
description = "Astro formatter package";
};
};
extraDiagnostics = {
@ -137,16 +139,6 @@ in {
cfg.lsp.servers;
})
(mkIf cfg.format.enable {
vim.formatter.conform-nvim = {
enable = true;
setupOpts.formatters_by_ft.astro = [cfg.format.type];
setupOpts.formatters.${cfg.format.type} = {
command = getExe cfg.format.package;
};
};
})
(mkIf cfg.extraDiagnostics.enable {
vim.diagnostics.nvim-lint = {
enable = true;