64 lines
1.8 KiB
Lua
64 lines
1.8 KiB
Lua
local M = {}
|
|
|
|
function M.config()
|
|
local status_ok, null_ls = pcall(require, "null-ls")
|
|
if not status_ok then
|
|
return
|
|
end
|
|
|
|
local augroup = vim.api.nvim_create_augroup("LspFormatting", {})
|
|
null_ls.setup {
|
|
debug = false,
|
|
sources = {
|
|
-- https://github.com/jose-elias-alvarez/null-ls.nvim/blob/main/doc/BUILTINS.md
|
|
|
|
-- Python
|
|
|
|
-- pip install black
|
|
null_ls.builtins.formatting.black,
|
|
|
|
-- pip install isort
|
|
null_ls.builtins.formatting.isort,
|
|
|
|
|
|
-- JavaScript / TypeScript
|
|
|
|
-- sudo pacman -S prettierd
|
|
-- sudo npm install -g @fsouza/prettierd
|
|
null_ls.builtins.formatting.prettierd.with({
|
|
disabled_filetypes = { "html", "markdown" },
|
|
condition = function(utils)
|
|
return utils.root_has_file({ ".prettierrc.yml" })
|
|
end,
|
|
}),
|
|
|
|
-- sudo pacman -S eslint_d
|
|
-- sudo npm install -g eslint_d
|
|
null_ls.builtins.diagnostics.eslint_d.with({
|
|
diagnostic_config = {
|
|
virtual_text = false,
|
|
severity_sort = true,
|
|
},
|
|
condition = function(utils)
|
|
return utils.root_has_file({ ".eslintrc.js" })
|
|
end,
|
|
}),
|
|
},
|
|
-- Format before save
|
|
on_attach = function(client, 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()
|
|
vim.lsp.buf.format({ bufnr = bufnr })
|
|
end,
|
|
})
|
|
end
|
|
end,
|
|
}
|
|
end
|
|
|
|
return M
|