Add Mason and Null-ls plugins for Neovim

This commit is contained in:
PeteChu 2023-04-09 14:18:18 +07:00
parent a9de446ed3
commit bc702160c2
3 changed files with 55 additions and 12 deletions

View File

@ -467,18 +467,6 @@ local servers = {
-- pyright = {}, -- pyright = {},
-- rust_analyzer = {}, -- rust_analyzer = {},
-- tsserver = {}, -- tsserver = {},
efm = {
init_options = { documentFormatting = true },
settings = {
rootMarkers = { ".git/" },
languages = {
prettier = {
formatCommand = 'prettierd "${INPUT}"',
formatStdin = true,
}
}
}
},
lua_ls = { lua_ls = {
Lua = { Lua = {
workspace = { checkThirdParty = false }, workspace = { checkThirdParty = false },

View File

@ -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,
}

View File

@ -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
}