neovim/lua/plugins/lsp/mason.lua

140 lines
3.7 KiB
Lua

-- Install and configure mason.nvim which will install automatically the needed
-- LSP
return {
"williamboman/mason.nvim",
dependencies = {
"williamboman/mason-lspconfig.nvim",
"WhoIsSethDaniel/mason-tool-installer.nvim",
},
config = function()
-- Import mason
local mason = require("mason")
-- Import mason-lspconfig
local mason_lspconfig = require("mason-lspconfig")
-- Import lspconfig
local lspconfig = require("lspconfig")
local util = require("lspconfig.util")
-- Import mason-tool-installer
local mason_tool_installer = require("mason-tool-installer")
-- Activate mason and set icones
mason.setup({
ui = {
icons = {
package_installed = "",
package_pending = "",
package_uninstalled = "",
},
},
})
mason_tool_installer.setup({
ensure_installed = {
"black",
"isort",
"prettier",
"stylua",
"tree-sitter-cli",
}
})
mason_lspconfig.setup({
-- LSP to be installed by default
-- Available LSP: https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md
-- LSP can be installed with :Mason
-- But installing LSP through the following list is better
ensure_installed = {
"cssls",
"html",
"jsonls",
"lua_ls",
"marksman",
"pylsp",
"yamlls",
},
handlers = {
-- Function called for each LSP from the ensure_installed list loaded
function(server_name)
-- Activate all LSP from the ensure_installed list with its default
-- configuration
lspconfig[server_name].setup({})
end,
-- Then, configure each LSP as needed
-- See https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md
--
-- To deactivate a LSP:
-- lsp_name = require("lsp-zero").noop,
-- The LSP name before`= function()` has to be the same than after
-- `lspconfig.`
-- The first one is the mason_lspconfig key, the seconde one is the
-- lspconfig key. They are identical to the ensure_installed entries.
-- https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#pylsp
pylsp = function()
lspconfig.pylsp.setup({
settings = {
pylsp = {
plugins = {
pyflakes = { enabled = false },
pycodestyle = {
enabled = true,
ignore = { "E501" },
},
},
},
},
})
end,
lua_ls = function()
lspconfig.lua_ls.setup({
settings = {
Lua = {
diagnostics = {
-- Force LSP to recognize global variable `vim`.
globals = { "vim" },
disable = { "missing-fields" },
}
}
}
})
end,
jsonls = function()
lspconfig.jsonls.setup({
settings = {
json = {
schemas = require("schemastore").json.schemas(),
validate = { enable = true },
}
}
})
end,
marksman = function()
lspconfig.marksman.setup({
setting = {
filetypes = {
"markdown",
"quarto",
},
root_dir = util.root_pattern(
'.git',
'.marksman.toml',
'_quarto.yml'
),
}
})
end
},
})
end,
}