neovim/lua/plugins/lsp/mason.lua

121 lines
3.3 KiB
Lua
Raw Normal View History

-- 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")
-- 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",
"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.lua_ls.setup({
settings = {
json = {
schemas = require("schemastore").json.schemas(),
validate = { enable = true },
}
}
})
end
},
})
end,
}