Migrate to mason.nvim and setup jdtls

This commit is contained in:
Alexander Gehrke 2023-02-26 22:07:32 +01:00
parent 3a1ab705cb
commit 59ec8d490b
6 changed files with 92 additions and 27 deletions

View file

@ -1,8 +1,39 @@
local status, lsp_installer = pcall(require,"nvim-lsp-installer")
if (not status) then return end
local status1, mason = pcall(require, "mason")
local status2, mason_lspconfig = pcall(require, "mason-lspconfig")
if (not (status1 and status2)) then return end
lsp_installer.on_server_ready(function(server)
local opts = {}
return function(on_attach)
mason.setup {}
mason_lspconfig.setup {
ensure_installed = { 'jdtls', 'lua_ls' }
}
server:setup(opts)
end)
local no_autosetup = {
jdtls = true
}
local extra_config = {
lua_ls = {
on_attach = on_attach,
settings = {
Lua = {
diagnostics = { globals = { 'vim' } },
workspace = {
library = vim.api.nvim_get_runtime_file("", true),
},
telemetry = { enable = false },
},
},
}
}
mason_lspconfig.setup_handlers {
function(server_name)
if (not no_autosetup[server_name]) then
require("lspconfig")[server_name].setup(
extra_config[server_name] or { on_attach = on_attach }
)
end
end,
}
end

View file

@ -42,7 +42,7 @@ return function(on_attach)
-- NOTE: You may or may not want java included here. You will need it if you
-- want basic Java support but it may also conflict if you are using
-- something like nvim-jdtls which also works on a java filetype autocmd.
pattern = { "scala", "sbt", "java" },
pattern = { "scala", "sbt" },
callback = function()
require("metals").initialize_or_attach(metals_config)
end,