nvim-config/lua/configs/null-ls.lua

69 lines
1.6 KiB
Lua
Raw Normal View History

2022-03-01 02:58:43 +00:00
local M = {}
2022-05-01 17:43:11 +00:00
2022-03-01 02:58:43 +00:00
function M.config()
2023-01-10 18:21:09 +00:00
local status_ok, null_ls = pcall(require, 'null-ls')
2022-03-01 02:58:43 +00:00
if not status_ok then
return
end
2023-01-10 18:21:09 +00:00
local augroup = vim.api.nvim_create_augroup('LspFormatting', {})
null_ls.setup({
2022-03-01 02:58:43 +00:00
debug = false,
sources = {
2023-01-10 18:21:09 +00:00
-- https://github.com/jose-elias-alvarez/null-ls.nvim/blob/main/doc/BUILTINS.md
2023-01-10 18:21:09 +00:00
-- Lua
2023-01-10 18:21:09 +00:00
-- sudo pacman -S stylua
-- https://github.com/JohnnyMorganz/StyLua/releases
null_ls.builtins.formatting.stylua,
-- Python
-- pip install black
null_ls.builtins.formatting.black,
2023-01-10 18:21:09 +00:00
-- pip install isort
null_ls.builtins.formatting.isort,
2023-01-10 18:21:09 +00:00
-- JavaScript / TypeScript
2023-01-10 18:21:09 +00:00
-- sudo pacman -S prettierd
-- sudo npm install -g @fsouza/prettierd
null_ls.builtins.formatting.prettierd.with({
2023-01-10 18:21:09 +00:00
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({
2023-01-10 18:21:09 +00:00
diagnostic_config = {
virtual_text = false,
severity_sort = true,
},
condition = function(utils)
return utils.root_has_file({ '.eslintrc.js' })
end,
}),
2022-03-01 02:58:43 +00:00
},
-- Format before save
2023-01-10 18:21:09 +00:00
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,
})
2022-03-01 02:58:43 +00:00
end
return M