diff options
| author | Tomas Slusny <slusnucky@gmail.com> | 2025-09-30 06:05:23 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-09-29 21:05:23 -0700 |
| commit | 61d71943d8a527f8677d25a8c33be83ee99035fe (patch) | |
| tree | f94d96e1ef303254af3393f68fa92de72a04589a /lsp | |
| parent | docs: update configs.md (diff) | |
| download | nvim-lspconfig-61d71943d8a527f8677d25a8c33be83ee99035fe.tar nvim-lspconfig-61d71943d8a527f8677d25a8c33be83ee99035fe.tar.gz nvim-lspconfig-61d71943d8a527f8677d25a8c33be83ee99035fe.tar.bz2 nvim-lspconfig-61d71943d8a527f8677d25a8c33be83ee99035fe.tar.lz nvim-lspconfig-61d71943d8a527f8677d25a8c33be83ee99035fe.tar.xz nvim-lspconfig-61d71943d8a527f8677d25a8c33be83ee99035fe.tar.zst nvim-lspconfig-61d71943d8a527f8677d25a8c33be83ee99035fe.zip | |
fix(jdtls): use project-local workspace dir, remove unused options #4105
- https://github.com/eclipse-jdtls/eclipse.jdt.ls?tab=readme-ov-file#running-from-the-command-line:
`-data` dir needs to be project-local and not shared. override cmd with
function. also use stdpath.cache like other lsp servers already do
- https://github.com/eclipse-jdtls/eclipse.jdt.ls/wiki/Running-the-JAVA-LS-server-from-the-command-line#initialize-request
`jvm_args`, `workspace`, `os_config` are not part of jdtls init_options
- https://github.com/eclipse-jdtls/eclipse.jdt.ls/blob/dbe1db974e9b4b472b8b1063fe7e5e7fc2a1fb7f/org.eclipse.jdt.ls.product/scripts/jdtls.py#L102
jdtls already sets correct shared configuration path, `-configuration`
is not needed (and it is os-specific value so current config is wrong)
Closes #4103
Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
Diffstat (limited to 'lsp')
| -rw-r--r-- | lsp/jdtls.lua | 59 |
1 files changed, 30 insertions, 29 deletions
diff --git a/lsp/jdtls.lua b/lsp/jdtls.lua index 728f5907..13661bcf 100644 --- a/lsp/jdtls.lua +++ b/lsp/jdtls.lua @@ -32,22 +32,8 @@ --- vim.lsp.config('jdtls', { cmd = { 'jdtls' } }) --- ``` -local env = { - HOME = vim.uv.os_homedir(), - XDG_CACHE_HOME = os.getenv 'XDG_CACHE_HOME', - JDTLS_JVM_ARGS = os.getenv 'JDTLS_JVM_ARGS', -} - -local function get_cache_dir() - return env.XDG_CACHE_HOME and env.XDG_CACHE_HOME or env.HOME .. '/.cache' -end - local function get_jdtls_cache_dir() - return get_cache_dir() .. '/jdtls' -end - -local function get_jdtls_config_dir() - return get_jdtls_cache_dir() .. '/config' + return vim.fn.stdpath('cache') .. '/jdtls' end local function get_jdtls_workspace_dir() @@ -55,8 +41,9 @@ local function get_jdtls_workspace_dir() end local function get_jdtls_jvm_args() + local env = os.getenv('JDTLS_JVM_ARGS') local args = {} - for a in string.gmatch((env.JDTLS_JVM_ARGS or ''), '%S+') do + for a in string.gmatch((env or ''), '%S+') do local arg = string.format('--jvm-arg=%s', a) table.insert(args, arg) end @@ -85,20 +72,34 @@ local root_markers2 = { ---@type vim.lsp.Config return { - cmd = { - 'jdtls', - '-configuration', - get_jdtls_config_dir(), - '-data', - get_jdtls_workspace_dir(), - get_jdtls_jvm_args(), - }, + ---@param dispatchers? vim.lsp.rpc.Dispatchers + ---@param config vim.lsp.Config + cmd = function(dispatchers, config) + local workspace_dir = get_jdtls_workspace_dir() + local data_dir = workspace_dir + + if config.root_markers then + local root_dir = vim.fs.root(0, config.root_markers) + if root_dir then + data_dir = data_dir .. '/' .. vim.fn.fnamemodify(root_dir, ':p:h:t') + end + end + + local config_cmd = { + 'jdtls', + '-data', + data_dir, + get_jdtls_jvm_args(), + } + + return vim.lsp.rpc.start(config_cmd, dispatchers, { + cwd = config.cmd_cwd, + env = config.cmd_env, + detached = config.detached, + }) + end, filetypes = { 'java' }, root_markers = vim.fn.has('nvim-0.11.3') == 1 and { root_markers1, root_markers2 } or vim.list_extend(root_markers1, root_markers2), - init_options = { - workspace = get_jdtls_workspace_dir(), - jvm_args = {}, - os_config = nil, - }, + init_options = {}, } |
