37 lines
869 B
Lua
37 lines
869 B
Lua
local M = {}
|
|
|
|
function M.config()
|
|
local status_ok, null_ls = pcall(require, "null-ls")
|
|
if not status_ok then
|
|
return
|
|
end
|
|
|
|
-- Check supported formatters
|
|
-- https://github.com/jose-elias-alvarez/null-ls.nvim/tree/main/lua/null-ls/builtins/formatting
|
|
local formatting = null_ls.builtins.formatting
|
|
|
|
-- Check supported linters
|
|
-- https://github.com/jose-elias-alvarez/null-ls.nvim/tree/main/lua/null-ls/builtins/diagnostics
|
|
local diagnostics = null_ls.builtins.diagnostics
|
|
|
|
null_ls.setup {
|
|
debug = false,
|
|
sources = {
|
|
-- Set a formatter
|
|
formatting.prettierd,
|
|
formatting.black,
|
|
|
|
-- Set a linter
|
|
diagnostics.eslint_d,
|
|
},
|
|
-- Format before save
|
|
on_attach = function(client)
|
|
if client.resolved_capabilities.document_formatting then
|
|
vim.cmd "autocmd BufWritePre <buffer> lua vim.lsp.buf.formatting_sync()"
|
|
end
|
|
end,
|
|
}
|
|
end
|
|
|
|
return M
|