languages/css: add formatter support via prettier/prettierd

This commit is contained in:
raf 2024-02-28 00:33:40 +03:00
parent 57446f7afb
commit 9cb7239085
No known key found for this signature in database
GPG key ID: 02D1DD3FA08B6B29
2 changed files with 50 additions and 2 deletions

View file

@ -32,6 +32,33 @@
'';
};
};
defaultFormat = "prettier";
formats = {
prettier = {
package = pkgs.nodePackages.prettier;
nullConfig = ''
table.insert(
ls_sources,
null_ls.builtins.formatting.prettier.with({
command = "${cfg.format.package}/bin/prettier",
})
)
'';
};
prettierd = {
package = pkgs.prettierd;
nullConfig = ''
table.insert(
ls_sources,
null_ls.builtins.formatting.prettier.with({
command = "${cfg.format.package}/bin/prettierd",
})
)
'';
};
};
in {
options.vim.languages.css = {
enable = mkEnableOption "CSS language support";
@ -58,6 +85,22 @@ in {
default = servers.${cfg.lsp.server}.package;
};
};
format = {
enable = mkEnableOption "CSS formatting" // {default = config.vim.languages.enableFormat;};
type = mkOption {
description = "CSS formatter to use";
type = with types; enum (attrNames formats);
default = defaultFormat;
};
package = mkOption {
description = "CSS formatter package";
type = types.package;
default = formats.${cfg.format.type}.package;
};
};
};
config = mkIf cfg.enable (mkMerge [
@ -68,7 +111,12 @@ in {
(mkIf cfg.lsp.enable {
vim.lsp.lspconfig.enable = true;
vim.lsp.lspconfig.sources.tailwindcss-lsp = servers.${cfg.lsp.server}.lspConfig;
vim.lsp.lspconfig.sources.css-lsp = servers.${cfg.lsp.server}.lspConfig;
})
(mkIf cfg.format.enable {
vim.lsp.null-ls.enable = true;
vim.lsp.null-ls.sources.css-format = formats.${cfg.format.type}.nullConfig;
})
]);
}

View file

@ -51,7 +51,7 @@ in {
config = mkIf cfg.enable (mkMerge [
(mkIf cfg.lsp.enable {
vim.lsp.lspconfig.enable = true;
vim.lsp.lspconfig.sources.css-lsp = servers.${cfg.lsp.server}.lspConfig;
vim.lsp.lspconfig.sources.tailwindcss-lsp = servers.${cfg.lsp.server}.lspConfig;
})
]);
}