Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

languages: add terraform language support #182

Merged
merged 1 commit into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions configuration.nix
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ inputs: let
dart.enable = isMaximal;
elixir.enable = false;
bash.enable = isMaximal;
terraform.enable = isMaximal;
};

vim.visuals = {
Expand Down
1 change: 1 addition & 0 deletions modules/languages/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ in {
./java.nix
./lua.nix
./php.nix
./terraform.nix
];

options.vim.languages = {
Expand Down
46 changes: 46 additions & 0 deletions modules/languages/terraform.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
pkgs,
config,
lib,
...
}: let
inherit (lib) nvim mkEnableOption mkOption types mkIf mkMerge;

cfg = config.vim.languages.terraform;
in {
options.vim.languages.terraform = {
enable = mkEnableOption "Terraform/HCL support";

treesitter = {
enable = mkEnableOption "Terraform treesitter" // {default = config.vim.languages.enableTreesitter;};
package = nvim.types.mkGrammarOption pkgs "terraform";
};

lsp = {
enable = mkEnableOption "Terraform LSP support (terraform-ls)" // {default = config.vim.languages.enableLSP;};

package = mkOption {
description = "terraform-ls package";
type = with types; package;
default = pkgs.terraform-ls;
};
};
};
config = mkIf cfg.enable (mkMerge [
(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.terraform-ls = ''
lspconfig.terraformls.setup {
capabilities = capabilities,
on_attach=default_on_attach,
cmd = {"${cfg.lsp.package}/bin/terraform-ls", "serve"},
}
'';
})
]);
}
Loading