Skip to content

Commit

Permalink
requested improvements
Browse files Browse the repository at this point in the history
forgotten save

typo (lsp <-> format)
  • Loading branch information
ppenguin committed Nov 12, 2024
1 parent ce9d7ee commit 4d4235e
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions modules/plugins/languages/hcl.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,27 @@

defaultServer = "terraform-ls";
servers = {
terraform-ls = rec {
terraform-ls = {
package = pkgs.terraform-ls;
lspConfig = ''
lspconfig.terraformls.setup {
capabilities = capabilities,
on_attach=default_on_attach,
cmd = {"${lib.getExe package}", "serve"},
cmd = {"${lib.getExe cfg.lsp.package}", "serve"},
}
'';
};
};

defaultFormat = "hclfmt";
formats = {
hclfmt = rec {
hclfmt = {
package = pkgs.hclfmt;
nullConfig = ''
table.insert(
ls_sources,
null_ls.builtins.formatting.hclfmt.with({
command = "${lib.getExe package}",
command = "${lib.getExe cfg.format.package}",
})
)
'';
Expand All @@ -53,33 +53,34 @@ in {
enable = mkEnableOption "HCL LSP support (terraform-ls)" // {default = config.vim.languages.enableLSP;};
# TODO: (maybe, is it better?) it would be cooler to use vscode-extensions.hashicorp.hcl probably, shouldn't be too hard
package = mkOption {
description = "HCL language server package (terraform-ls)";
type = package;
default = servers.${defaultServer}.package;
description = "HCL language server package (terraform-ls)";
};
};

format = {
enable = mkOption {
description = "Enable HCL formatting";
type = bool;
default = config.vim.languages.enableFormat;
description = "Enable HCL formatting";
};
type = mkOption {
description = "HCL formatter to use";
type = enum (attrNames formats);
default = defaultFormat;
description = "HCL formatter to use";
};
package = mkOption {
description = "HCL formatter package";
type = package;
default = formats.${cfg.format.type}.package;
description = "HCL formatter package";
};
};
};

config = mkIf cfg.enable (mkMerge [
{
# hcl style official: https://developer.hashicorp.com/terraform/language/style#code-formatting
vim.pluginRC.hcl = ''
vim.api.nvim_create_autocmd("FileType", {
pattern = "hcl",
Expand Down

0 comments on commit 4d4235e

Please sign in to comment.