Compare commits

...

6 commits

Author SHA1 Message Date
ppenguin
5e67a982e7
Merge ce9d7ee870 into 8ff50562d7 2024-10-31 17:58:45 +00:00
ppenguin
ce9d7ee870
cleanup, add formatter 2024-10-31 18:58:38 +01:00
ppenguin
037075f52d
Merge branch 'main' into add-hcl-not-terraform 2024-10-31 17:28:28 +01:00
ppenguin
8ff50562d7 fix markdown-preview config error
Some checks failed
Set up binary cache / cachix (default) (push) Has been cancelled
Set up binary cache / cachix (maximal) (push) Has been cancelled
Set up binary cache / cachix (nix) (push) Has been cancelled
Validate flake & check formatting / Validate Flake (push) Has been cancelled
Validate flake & check formatting / Formatting via Alejandra (push) Has been cancelled
Build and deploy documentation / Check latest commit (push) Has been cancelled
Build and deploy documentation / publish (push) Has been cancelled
2024-10-30 12:03:39 +00:00
raf
eb288de4cf
Merge branch 'main' into add-hcl-not-terraform 2024-09-20 15:52:42 +00:00
ppenguin
5952e60f0f
add language HCL
Terraform doesn't register hcl and doesn't offer good DX if manually set
for editing e.g. nomad HCL files.

Incl. reformat with alejandra
2024-08-30 16:31:44 +02:00
3 changed files with 120 additions and 4 deletions

View file

@ -8,6 +8,7 @@ in {
./css.nix ./css.nix
./elixir.nix ./elixir.nix
./go.nix ./go.nix
./hcl.nix
./html.nix ./html.nix
./java.nix ./java.nix
./lua.nix ./lua.nix

View file

@ -0,0 +1,116 @@
{
config,
pkgs,
lib,
...
}: let
inherit (builtins) attrNames;
inherit (lib.options) mkEnableOption mkOption;
inherit (lib.modules) mkIf mkMerge;
inherit (lib.types) package bool enum;
inherit (lib.nvim.types) mkGrammarOption;
cfg = config.vim.languages.hcl;
defaultServer = "terraform-ls";
servers = {
terraform-ls = rec {
package = pkgs.terraform-ls;
lspConfig = ''
lspconfig.terraformls.setup {
capabilities = capabilities,
on_attach=default_on_attach,
cmd = {"${lib.getExe package}", "serve"},
}
'';
};
};
defaultFormat = "hclfmt";
formats = {
hclfmt = rec {
package = pkgs.hclfmt;
nullConfig = ''
table.insert(
ls_sources,
null_ls.builtins.formatting.hclfmt.with({
command = "${lib.getExe package}",
})
)
'';
};
};
in {
options.vim.languages.hcl = {
enable = mkEnableOption "HCL support";
treesitter = {
enable = mkEnableOption "HCL treesitter" // {default = config.vim.languages.enableTreesitter;};
package = mkGrammarOption pkgs "hcl";
};
lsp = {
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;
};
};
format = {
enable = mkOption {
description = "Enable HCL formatting";
type = bool;
default = config.vim.languages.enableFormat;
};
type = mkOption {
description = "HCL formatter to use";
type = enum (attrNames formats);
default = defaultFormat;
};
package = mkOption {
description = "HCL formatter package";
type = package;
default = formats.${cfg.format.type}.package;
};
};
};
config = mkIf cfg.enable (mkMerge [
{
vim.pluginRC.hcl = ''
vim.api.nvim_create_autocmd("FileType", {
pattern = "hcl",
callback = function(opts)
local bo = vim.bo[opts.buf]
bo.tabstop = 2
bo.shiftwidth = 2
bo.softtabstop = 2
end
})
local ft = require('Comment.ft')
ft
.set('hcl', '#%s')
'';
}
(mkIf cfg.treesitter.enable {
vim.treesitter.enable = true;
vim.treesitter.grammars = [cfg.treesitter.package];
})
(mkIf cfg.lsp.enable {
vim.lsp.lspconfig.enable = true;
vim.lsp.lspconfig.sources = lib.optionalAttrs (! config.vim.languages.terraform.lsp.enable) {
terraform-ls = servers.${cfg.lsp.server}.lspConfig;
};
})
(mkIf cfg.format.enable {
vim.lsp.null-ls.enable = true;
vim.lsp.null-ls.sources.hcl-format = formats.${cfg.format.type}.nullConfig;
})
]);
}

View file

@ -4,9 +4,8 @@
lib, lib,
... ...
}: let }: let
inherit (lib.strings) stringLength concatMapStringsSep; inherit (lib.strings) concatMapStringsSep;
inherit (lib.modules) mkIf; inherit (lib.modules) mkIf;
cfg = config.vim.utility.preview.markdownPreview; cfg = config.vim.utility.preview.markdownPreview;
in { in {
config = mkIf cfg.enable { config = mkIf cfg.enable {
@ -19,8 +18,8 @@ in {
mkdp_filetypes = [(concatMapStringsSep ", " (x: "'" + x + "'") cfg.filetypes)]; mkdp_filetypes = [(concatMapStringsSep ", " (x: "'" + x + "'") cfg.filetypes)];
mkdp_command_for_global = cfg.alwaysAllowPreview; mkdp_command_for_global = cfg.alwaysAllowPreview;
mkdp_open_to_the_world = cfg.broadcastServer; mkdp_open_to_the_world = cfg.broadcastServer;
mkdp_open_ip = mkIf (stringLength cfg.customIP > 0) cfg.customIP; mkdp_open_ip = cfg.customIP;
mkdp_port = mkIf (stringLength cfg.customPort > 0) cfg.customPort; mkdp_port = cfg.customPort;
}; };
}; };
} }