Skip to content

Commit

Permalink
languages/css: add formatter support via prettier/prettierd
Browse files Browse the repository at this point in the history
  • Loading branch information
NotAShelf committed Feb 27, 2024
1 parent 57446f7 commit 9cb7239
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
50 changes: 49 additions & 1 deletion modules/languages/css.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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 [
Expand All @@ -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;
})
]);
}
2 changes: 1 addition & 1 deletion modules/languages/tailwind.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
})
]);
}

0 comments on commit 9cb7239

Please sign in to comment.