dotfiles/.dotfiles/nvchad/custom/configs/none-ls.lua
2024-01-31 11:26:31 +01:00

34 lines
932 B
Lua

local none_ls = require("null-ls")
local augroup = vim.api.nvim_create_augroup("LspFormatting", {})
local opts = {
sources = {
-- gomft
none_ls.builtins.formatting.gofmt,
-- goimports-reviser (https://github.com/incu6us/goimports-reviser)
none_ls.builtins.formatting.goimports_reviser,
-- golangci-lint
none_ls.builtins.diagnostics.golangci_lint,
},
on_attach = function(client, bufnr)
-- check if there's any commands pre-running on the current buffer,
-- clear those and then run out own format command
if client.supports_method("textDocument/formatting") then
vim.api.nvim_clear_autocmds({
group = augroup,
buffer = bufnr,
})
vim.api.nvim_create_autocmd("BufWritePre", {
group = augroup,
buffer = bufnr,
callback = function ()
vim.lsp.buf.format({ bufnr = bufnr })
end
})
end
end,
}
return opts