lazyvim/lua/lazyvim/plugins/extras/lang/terraform.lua
MiguelNdeCarvalho 981d9cb1ed
fix(terraform): disable semantic tokens to prevent editor hangs
Workaround for terraform-ls sending invalid semantic tokens that cause

Neovim 0.12 to freeze when opening terraform files with heredoc blocks.

See: https://github.com/hashicorp/terraform-ls/issues/2094
2026-03-30 17:55:27 +01:00

94 lines
2.3 KiB
Lua

return {
recommended = function()
return LazyVim.extras.wants({
ft = { "terraform", "hcl" },
root = ".terraform",
})
end,
{
"nvim-treesitter/nvim-treesitter",
opts = { ensure_installed = { "terraform", "hcl" } },
},
{
"neovim/nvim-lspconfig",
opts = {
servers = {
terraformls = {},
},
setup = {
terraformls = function(_, opts)
-- workaround for terraform-ls sending invalid semantic tokens
-- https://github.com/hashicorp/terraform-ls/issues/2094
Snacks.util.lsp.on({ name = "terraformls" }, function(_, client)
client.server_capabilities.semanticTokensProvider = nil
end)
-- end workaround
end,
},
},
},
-- ensure terraform tools are installed
{
"mason-org/mason.nvim",
opts = { ensure_installed = { "tflint" } },
},
{
"nvimtools/none-ls.nvim",
optional = true,
opts = function(_, opts)
local null_ls = require("null-ls")
opts.sources = vim.list_extend(opts.sources or {}, {
null_ls.builtins.formatting.packer,
null_ls.builtins.formatting.terraform_fmt,
null_ls.builtins.diagnostics.terraform_validate,
})
end,
},
{
"mfussenegger/nvim-lint",
optional = true,
opts = {
linters_by_ft = {
terraform = { "terraform_validate" },
tf = { "terraform_validate" },
},
},
},
{
"stevearc/conform.nvim",
optional = true,
opts = {
formatters_by_ft = {
hcl = { "packer_fmt" },
terraform = { "terraform_fmt" },
tf = { "terraform_fmt" },
["terraform-vars"] = { "terraform_fmt" },
},
},
},
{
"nvim-telescope/telescope.nvim",
optional = true,
specs = {
{
"ANGkeith/telescope-terraform-doc.nvim",
ft = { "terraform", "hcl" },
config = function()
LazyVim.on_load("telescope.nvim", function()
require("telescope").load_extension("terraform_doc")
end)
end,
},
{
"cappyzawa/telescope-terraform.nvim",
ft = { "terraform", "hcl" },
config = function()
LazyVim.on_load("telescope.nvim", function()
require("telescope").load_extension("terraform")
end)
end,
},
},
},
}