neovim: Use nvim-jdtls

23.11
Simon Bruder 2023-10-11 12:08:47 +02:00
parent ace6f449c3
commit 95ae4c03c4
Signed by: simon
GPG Key ID: 8D3C82F9F309F8EC
2 changed files with 60 additions and 4 deletions

View File

@ -84,6 +84,7 @@ in
luasnip
neogit
nvim-cmp
nvim-jdtls
nvim-lspconfig
nvim-solarized-lua
nvim-treesitter

View File

@ -299,10 +299,6 @@ lsp.hls.setup {
on_attach = on_attach,
root_dir = lsp.util.root_pattern('*.cabal', 'stack.yaml', 'cabal.project', 'package.yaml', 'hie.yaml', '.git'),
}
lsp.jdtls.setup {
on_attach = on_attach,
cmd = {'jdt-language-server', '-configuration', '/home/simon/.cache/jdtls/config', '-data', '/home/simon/.cache/jdtls/workspace'}, -- copied from upstream, but changed executable name
}
lsp.ltex.setup {
on_attach = on_attach,
settings = {
@ -361,6 +357,65 @@ lsp.rust_analyzer.setup {
},
}
vim.api.nvim_create_autocmd({"FileType"}, {
pattern = "java",
callback = function()
local jdtls = require('jdtls')
local config = {
cmd = {
'jdt-language-server',
'-configuration', vim.fn.expand('~') .. '/.cache/jdtls/config',
'-data', vim.fn.expand('~') .. '/.local/share/jdtls/workspace/' .. vim.fn.fnamemodify(vim.fn.getcwd(), ':p:h:t'),
},
-- https://github.com/eclipse/eclipse.jdt.ls/wiki/Running-the-JAVA-LS-server-from-the-command-line#initialize-request
settings = {
java = {
signatureHelp = { enabled = true };
completion = {
favoriteStaticMembers = {
},
filteredTypes = {
"com.sun.*",
"java.awt.*",
"jdk.*",
"sun.*",
},
};
maven = {
downloadSources = true,
},
implementationsCodeLens = {
enabled = true,
},
referencesCodeLens = {
enabled = true,
},
},
},
on_attach = function(client, bufnr)
on_attach(client, bufnr) -- global lsp configuration
jdtls.setup.add_commands()
local opts = { noremap = true, silent = true }
vim.keymap.set('n', '<Leader>jo', jdtls.organize_imports, opts)
vim.keymap.set('n', '<Leader>jtc', jdtls.test_class, opts)
vim.keymap.set('n', '<Leader>jtm', jdtls.test_nearest_method, opts)
vim.keymap.set('n', '<Leader>jev', jdtls.extract_variable, opts)
vim.keymap.set('v', '<Leader>jem', [[<ESC><CMD>lua require('jdtls').extract_method(true)<CR>]], opts)
vim.keymap.set('n', '<Leader>jec', jdtls.extract_constanconstant, opts)
end,
}
jdtls.start_or_attach(config)
end
})
require('trouble').setup {}
-- Tree Sitter