feat: add terraform lsp & lint

This commit is contained in:
Bogdan Buduroiu 2025-02-27 15:49:51 +08:00
parent dc0e0fa634
commit aaab5e3b57
Signed by: bruvduroiu
GPG key ID: A8722B2334DE9499
3 changed files with 63 additions and 60 deletions

View file

@ -1,24 +1,25 @@
local options = { local options = {
formatters_by_ft = { formatters_by_ft = {
lua = { "stylua" }, lua = { "stylua" },
css = { "prettier" }, css = { "prettier" },
html = { "prettier" }, html = { "prettier" },
python = { "ruff_format", "ruff_fix", "ruff_organize_imports" }, python = { "ruff_format", "ruff_fix", "ruff_organize_imports" },
go = { "goimports", "gofmt" }, tf = { "tflint", "terraform-ls" },
json = { "jq" }, go = { "goimports", "gofmt" },
}, json = { "jq" },
},
format_on_save = { format_on_save = {
-- These options will be passed to conform.format() -- These options will be passed to conform.format()
timeout_ms = 500, timeout_ms = 500,
lsp_format = "fallback", lsp_format = "fallback",
}, },
-- Set the log level. Use `:ConformInfo` to see the location of the log file. -- Set the log level. Use `:ConformInfo` to see the location of the log file.
log_level = vim.log.levels.ERROR, log_level = vim.log.levels.ERROR,
-- Conform will notify you when a formatter errors -- Conform will notify you when a formatter errors
notify_on_error = true, notify_on_error = true,
-- Conform will notify you when no formatters are available for the buffer -- Conform will notify you when no formatters are available for the buffer
notify_no_formatters = true, notify_no_formatters = true,
} }
return options return options

View file

@ -1,53 +1,54 @@
local configs = require "nvchad.configs.lspconfig" local configs = require("nvchad.configs.lspconfig")
configs.defaults() configs.defaults()
local servers = { local servers = {
html = {}, html = {},
cssls = {}, cssls = {},
gopls = { gopls = {
analyses = { analyses = {
unusedparams = true, unusedparams = true,
}, },
staticcheck = true, staticcheck = true,
gofumpt = true, gofumpt = true,
}, },
ruff = { ruff = {
lint = { lint = {
run = "onSave", run = "onSave",
}, },
}, },
zls = {}, zls = {},
terraformls = {},
pyright = { pyright = {
settings = { settings = {
python = { python = {
analysis = { analysis = {
autoSearchPaths = true, autoSearchPaths = true,
typeCheckingMode = "basic", typeCheckingMode = "basic",
}, },
venvPath = vim.fn.getcwd() .. "/.venv", venvPath = vim.fn.getcwd() .. "/.venv",
pythonPath = vim.fn.getcwd() .. "/.venv/bin/python3", pythonPath = vim.fn.getcwd() .. "/.venv/bin/python3",
}, },
}, },
}, },
ts_ls = { ts_ls = {
settings = { settings = {
completions = { completions = {
completeFunctionCalls = true, completeFunctionCalls = true,
}, },
}, },
}, },
} }
local on_attach = function(client, bufnr) local on_attach = function(client, bufnr)
configs.on_attach(client, bufnr) configs.on_attach(client, bufnr)
client.server_capabilities.documentFormattingProvider = true client.server_capabilities.documentFormattingProvider = true
end end
for name, opts in pairs(servers) do for name, opts in pairs(servers) do
opts.on_init = configs.on_init opts.on_init = configs.on_init
opts.on_attach = on_attach opts.on_attach = on_attach
opts.capabilities = configs.capabilities opts.capabilities = configs.capabilities
require("lspconfig")[name].setup(opts) require("lspconfig")[name].setup(opts)
end end

View file

@ -25,6 +25,7 @@ return {
"python", "python",
"typescript", "typescript",
"go", "go",
"terraform",
}, },
}, },
}, },