49 lines
1.3 KiB
Lua
49 lines
1.3 KiB
Lua
local fmt = require("null-ls").builtins.formatting
|
|
local dgn = require("null-ls").builtins.diagnostics
|
|
local cda = require("null-ls").builtins.code_actions
|
|
local augroup = vim.api.nvim_create_augroup("LspFormatting", {})
|
|
|
|
require("null-ls").setup({
|
|
sources = {
|
|
-- # FORMATTING #
|
|
fmt.trim_whitespace.with({
|
|
filetypes = { "text", "sh", "zsh", "yaml", "toml", "make", "conf" },
|
|
}),
|
|
-- NOTE:
|
|
-- 1. both needs to be enabled to so prettier can apply eslint fixes
|
|
-- 2. and prettierd should come first
|
|
fmt.prettierd,
|
|
fmt.eslint_d,
|
|
fmt.rustywind,
|
|
fmt.stylua,
|
|
fmt.shfmt,
|
|
-- # DIAGNOSTICS #
|
|
dgn.eslint_d,
|
|
dgn.tidy,
|
|
dgn.luacheck,
|
|
dgn.shellcheck,
|
|
dgn.luacheck.with({
|
|
extra_args = { "--globals", "vim", "--std", "luajit" },
|
|
}),
|
|
-- # CODE ACTIONS #
|
|
cda.gitsigns,
|
|
cda.eslint_d,
|
|
cda.shellcheck,
|
|
},
|
|
on_attach = function(client, bufnr)
|
|
-- require("plugins.lsp.lsp-utils").fmt_on_save(client)
|
|
require("plugins.lsp.lsp-utils").mappings(bufnr)
|
|
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()
|
|
-- on 0.8, you should use vim.lsp.buf.format({ bufnr = bufnr }) instead
|
|
vim.lsp.buf.formatting_sync()
|
|
end,
|
|
})
|
|
end
|
|
end,
|
|
})
|