|
32 | 32 | --- vim.lsp.config('jdtls', { cmd = { 'jdtls' } }) |
33 | 33 | --- ``` |
34 | 34 |
|
35 | | -local handlers = require 'vim.lsp.handlers' |
36 | | - |
37 | 35 | local env = { |
38 | 36 | HOME = vim.uv.os_homedir(), |
39 | 37 | XDG_CACHE_HOME = os.getenv 'XDG_CACHE_HOME', |
@@ -65,42 +63,6 @@ local function get_jdtls_jvm_args() |
65 | 63 | return unpack(args) |
66 | 64 | end |
67 | 65 |
|
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 | | - |
104 | 66 | ---@type vim.lsp.Config |
105 | 67 | return { |
106 | 68 | cmd = { |
@@ -128,11 +90,4 @@ return { |
128 | 90 | jvm_args = {}, |
129 | 91 | os_config = nil, |
130 | 92 | }, |
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 | | - }, |
138 | 93 | } |
0 commit comments