expand to advanced setup

This commit is contained in:
Baipyrus 2024-07-28 22:08:18 +02:00
parent a33a2ae8d8
commit 2da89bd3e7

View File

@ -200,9 +200,67 @@ return {
} }
local function jdtls_setup() local function jdtls_setup()
local project_name = vim.fn.fnamemodify(vim.fn.getcwd(), ':p:h:t')
-- calculate workspace dir
local workspace_dir = vim.fn.stdpath 'data' .. '/site/java/workspace-root/' .. project_name
-- get the mason install path
local install_path = require('mason-registry').get_package('jdtls'):get_install_path()
local jdtls_path = vim.fn.glob(install_path .. '/plugins/org.eclipse.equinox.launcher_*.jar')
-- try to detect sysname for config
local sysname = 'win'
if vim.fn.has 'unix' then
sysname = 'linux'
elseif vim.fn.has 'mac' then
sysname = 'mac'
end
-- set default config according to sysname
local config_path = install_path .. '/config_' .. sysname
-- See `:help vim.lsp.start_client` for an overview of the supported `config` options.
local config = { local config = {
cmd = { require('mason-registry').get_package('jdtls'):get_install_path() .. '/bin/jdtls' }, -- The command that starts the language server
root_dir = vim.fs.dirname(vim.fs.find({ 'gradlew', '.git', 'mvnw' }, { upward = true })[1]), -- See: https://github.com/eclipse/eclipse.jdt.ls#running-from-the-command-line
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',
'-Xmx1g',
'--add-modules=ALL-SYSTEM',
'--add-opens',
'java.base/java.util=ALL-UNNAMED',
'--add-opens',
'java.base/java.lang=ALL-UNNAMED',
'-jar',
jdtls_path,
'-configuration',
config_path,
'-data',
workspace_dir,
},
capabilities = capabilities,
root_dir = vim.fs.root(0, { '.git', 'mvnw', 'gradlew' }),
-- Here you can configure eclipse.jdt.ls specific settings
-- See https://github.com/eclipse/eclipse.jdt.ls/wiki/Running-the-JAVA-LS-server-from-the-command-line#initialize-request
-- for a list of options
settings = {
java = {},
},
-- Language server `initializationOptions`
-- See https://github.com/mfussenegger/nvim-jdtls#java-debug-installation
init_options = {
bundles = {},
},
} }
require('jdtls').start_or_attach(config) require('jdtls').start_or_attach(config)
end end