Nvim: add jdtls 🚀

This commit is contained in:
Marko Korhonen 2022-02-24 18:08:59 +02:00
parent d695658146
commit 9e0399fbed
4 changed files with 31 additions and 3 deletions

View file

@ -0,0 +1,19 @@
local nvim_local_dir = vim.fn.expand('~/.local/share/nvim')
local project_name = vim.fn.fnamemodify(vim.fn.getcwd(), ':p:h:t')
local workspace_dir = nvim_local_dir .. '/jdtls-workspaces/' .. project_name
require('jdtls').start_or_attach({
cmd = {
'java', '-Declipse.application=org.eclipse.jdt.ls.core.id1',
'-Dosgi.bundles.defaultStartLevel=4',
'-Declipse.product=org.eclipse.jdt.ls.core.product',
'-Dlog.protocol=true', '-Dlog.level=ALL', '-Xms1g',
'--add-modules=ALL-SYSTEM', '--add-opens',
'java.base/java.util=ALL-UNNAMED', '--add-opens',
'java.base/java.lang=ALL-UNNAMED', -- 💀
'-jar', nvim_local_dir ..
'/lsp_servers/jdtls/plugins/org.eclipse.equinox.launcher_1.6.400.v20210924-0641.jar',
'-configuration', nvim_local_dir .. '/lsp_servers/jdtls/config_linux',
'-data', workspace_dir
}
})

View file

@ -49,8 +49,10 @@ local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities)
-- Register a handler that will be called for all installed servers.
-- Alternatively, you may also register handlers on specific server instances instead (see example below).
lsp_installer.on_server_ready(function(server)
-- Don't setup jdtls here since it is done by nvim-jdtls
if server.name == "jdtls" then return end
local opts = {}
-- Lua specific settings
@ -79,6 +81,6 @@ lsp_installer.on_server_ready(function(server)
end
opts.on_attach = buf_map_keys
opts.capabilities = capabilities
opts.capabilities = capabilities
server:setup(opts)
end)

View file

@ -64,6 +64,9 @@ require('packer').startup(function()
-- Install LSP server executables
use 'williamboman/nvim-lsp-installer'
-- Additional LSP features for Java
use 'mfussenegger/nvim-jdtls'
-- Completion
use 'hrsh7th/nvim-cmp' -- Autocompletion plugin
use 'hrsh7th/cmp-nvim-lsp' -- LSP source for nvim-cmp