Nvim: jdtl: use on_attach from mason module

This commit is contained in:
Marko Korhonen 2023-11-17 16:48:28 +02:00
parent 92ab50ddfc
commit 6c6ce53837
No known key found for this signature in database
GPG Key ID: A7F78BCB859CD890
2 changed files with 36 additions and 23 deletions

View File

@ -2,6 +2,7 @@ local nvim_local_dir = vim.fn.expand("~/.local/share/nvim")
local lombok_jar = nvim_local_dir .. "/mason/packages/jdtls/lombok.jar"
local project_name = vim.fn.fnamemodify(vim.fn.getcwd(), ":p:h:t")
local workspace_dir = nvim_local_dir .. "/jdtls-workspaces/" .. project_name
local mason = require("plugins.mason")
require("jdtls").start_or_attach({
cmd = {
@ -41,10 +42,13 @@ require("jdtls").start_or_attach({
path = "/usr/lib/jvm/java-19-openjdk-amd64/",
},
},
handlers = {
["language/status"] = function() end,
},
capabilities = mason.get_capabilities(),
on_attach = mason.on_attach,
})
require("plugins.mason").map_keys()
function RunJava()
local function show_output(output)
vim.cmd("split")

View File

@ -1,34 +1,16 @@
local m = {}
function m.setup()
local function on_attach(client, bufnr)
-- Attach navic
require("nvim-navic").attach(client, bufnr)
-- Setup keybinds
m.map_keys()
end
-- Inform lsp about completion capabilities from cmp
local capabilities = require("cmp_nvim_lsp").default_capabilities()
-- Neovim hasn't added foldingRange to default capabilities, users must add it manually
-- for ufo
capabilities.textDocument.foldingRange = {
dynamicRegistration = false,
lineFoldingOnly = true,
}
require("mason").setup()
local mason_lsp = require("mason-lspconfig")
mason_lsp.setup()
local capabilities = m.get_capabilities()
mason_lsp.setup_handlers({
-- Default handler
function(server_name)
require("lspconfig")[server_name].setup({
on_attach = on_attach,
on_attach = m.on_attach,
capabilities = capabilities,
})
end,
@ -36,7 +18,7 @@ function m.setup()
-- Override lua_ls settings
["lua_ls"] = function()
require("lspconfig").lua_ls.setup({
on_attach = on_attach,
on_attach = m.on_attach,
capabilities = capabilities,
settings = {
Lua = {
@ -101,4 +83,31 @@ function m.map_keys()
})
end
function m.on_attach(client, bufnr)
-- Attach navic if document symbols are available
if client.server_capabilities.documentSymbolProvider then
require("nvim-navic").attach(client, bufnr)
end
-- Setup keybinds
m.map_keys()
end
function m.get_capabilities()
-- Combine built-in LSP and cmp cabaibilities
local capabilities = vim.tbl_deep_extend(
"force",
vim.lsp.protocol.make_client_capabilities(),
require("cmp_nvim_lsp").default_capabilities()
)
-- Neovim hasn't added foldingRange to default capabilities, users must add it manually
-- for ufo
--capabilities.textDocument.foldingRange = {
-- dynamicRegistration = false,
-- lineFoldingOnly = true,
--}
return capabilities
end
return m