Add Mason and Null-ls plugins for Neovim
This commit is contained in:
parent
a9de446ed3
commit
bc702160c2
12
init.lua
12
init.lua
|
@ -467,18 +467,6 @@ local servers = {
|
|||
-- pyright = {},
|
||||
-- rust_analyzer = {},
|
||||
-- tsserver = {},
|
||||
efm = {
|
||||
init_options = { documentFormatting = true },
|
||||
settings = {
|
||||
rootMarkers = { ".git/" },
|
||||
languages = {
|
||||
prettier = {
|
||||
formatCommand = 'prettierd "${INPUT}"',
|
||||
formatStdin = true,
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
lua_ls = {
|
||||
Lua = {
|
||||
workspace = { checkThirdParty = false },
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
return {
|
||||
"jay-babu/mason-null-ls.nvim",
|
||||
event = { "BufReadPre", "BufNewFile" },
|
||||
dependencies = {
|
||||
"williamboman/mason.nvim",
|
||||
"jose-elias-alvarez/null-ls.nvim",
|
||||
},
|
||||
config = function()
|
||||
require("mason-null-ls").setup({
|
||||
-- list of formatters & linters for mason to install
|
||||
ensure_installed = {
|
||||
"prettierd", -- ts/js formatter
|
||||
"eslint_d", -- ts/js linter
|
||||
},
|
||||
-- auto-install configured formatters & linters (with null-ls)
|
||||
automatic_installation = true,
|
||||
})
|
||||
end,
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
return {
|
||||
"jose-elias-alvarez/null-ls.nvim",
|
||||
config = function()
|
||||
local null_ls = require("null-ls")
|
||||
|
||||
local formatting = null_ls.builtins.formatting -- to setup formatters
|
||||
local diagnostics = null_ls.builtins.diagnostics -- to setup linters
|
||||
|
||||
local augroup = vim.api.nvim_create_augroup("LspFormatting", {})
|
||||
|
||||
null_ls.setup({
|
||||
sources = {
|
||||
formatting.prettierd,
|
||||
diagnostics.eslint_d
|
||||
},
|
||||
on_attach = function(current_client, bufnr)
|
||||
if current_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({
|
||||
filter = function(client)
|
||||
-- only use null-ls for formatting instead of lsp server
|
||||
return client.name == "null-ls"
|
||||
end,
|
||||
bufnr = bufnr,
|
||||
})
|
||||
end,
|
||||
})
|
||||
end
|
||||
end
|
||||
})
|
||||
end
|
||||
}
|
Loading…
Reference in New Issue