Skip to content

Commit 41b04ad

Browse files
authored
fix(jdtls): remove nonstandard WorkspaceEdit version handlers #4071
Remove custom handlers and version fix for WorkspaceEdit, as jdtls now conforms to the LSP spec (eclipse-jdtls/eclipse.jdt.ls#1742) See eclipse-jdtls/eclipse.jdt.ls#1695 for more background on why the workaround was introduced. The original problem was fixed in the upstream LSP server four years ago: remove the workaround.
1 parent bc09aa2 commit 41b04ad

File tree

1 file changed

+0
-45
lines changed

1 file changed

+0
-45
lines changed

lsp/jdtls.lua

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232
--- vim.lsp.config('jdtls', { cmd = { 'jdtls' } })
3333
--- ```
3434

35-
local handlers = require 'vim.lsp.handlers'
36-
3735
local env = {
3836
HOME = vim.uv.os_homedir(),
3937
XDG_CACHE_HOME = os.getenv 'XDG_CACHE_HOME',
@@ -65,42 +63,6 @@ local function get_jdtls_jvm_args()
6563
return unpack(args)
6664
end
6765

68-
-- TextDocument version is reported as 0, override with nil so that
69-
-- the client doesn't think the document is newer and refuses to update
70-
-- See: https://github.com/eclipse/eclipse.jdt.ls/issues/1695
71-
local function fix_zero_version(workspace_edit)
72-
if workspace_edit and workspace_edit.documentChanges then
73-
for _, change in pairs(workspace_edit.documentChanges) do
74-
local text_document = change.textDocument
75-
if text_document and text_document.version and text_document.version == 0 then
76-
text_document.version = nil
77-
end
78-
end
79-
end
80-
return workspace_edit
81-
end
82-
83-
local function on_textdocument_codeaction(err, actions, ctx)
84-
for _, action in ipairs(actions) do
85-
-- TODO: (steelsojka) Handle more than one edit?
86-
if action.command == 'java.apply.workspaceEdit' then -- 'action' is Command in java format
87-
action.edit = fix_zero_version(action.edit or action.arguments[1])
88-
elseif type(action.command) == 'table' and action.command.command == 'java.apply.workspaceEdit' then -- 'action' is CodeAction in java format
89-
action.edit = fix_zero_version(action.edit or action.command.arguments[1])
90-
end
91-
end
92-
93-
handlers[ctx.method](err, actions, ctx)
94-
end
95-
96-
local function on_textdocument_rename(err, workspace_edit, ctx)
97-
handlers[ctx.method](err, fix_zero_version(workspace_edit), ctx)
98-
end
99-
100-
local function on_workspace_applyedit(err, workspace_edit, ctx)
101-
handlers[ctx.method](err, fix_zero_version(workspace_edit), ctx)
102-
end
103-
10466
---@type vim.lsp.Config
10567
return {
10668
cmd = {
@@ -128,11 +90,4 @@ return {
12890
jvm_args = {},
12991
os_config = nil,
13092
},
131-
handlers = {
132-
-- Due to an invalid protocol implementation in the jdtls we have to conform these to be spec compliant.
133-
-- https://github.com/eclipse/eclipse.jdt.ls/issues/376
134-
['textDocument/codeAction'] = on_textdocument_codeaction,
135-
['textDocument/rename'] = on_textdocument_rename,
136-
['workspace/applyEdit'] = on_workspace_applyedit,
137-
},
13893
}

0 commit comments

Comments
 (0)