diff options
| author | Russ Adams <russ.adams@gmail.com> | 2021-11-01 19:43:58 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-11-01 16:43:58 -0700 |
| commit | 756549de506bcf9cf9361e87c8b360154b9d7235 (patch) | |
| tree | 9721557fcc544d7deeb0b6a0cf231d8a5fded208 /lua | |
| parent | docs: update CONFIG.md (diff) | |
| download | nvim-lspconfig-756549de506bcf9cf9361e87c8b360154b9d7235.tar nvim-lspconfig-756549de506bcf9cf9361e87c8b360154b9d7235.tar.gz nvim-lspconfig-756549de506bcf9cf9361e87c8b360154b9d7235.tar.bz2 nvim-lspconfig-756549de506bcf9cf9361e87c8b360154b9d7235.tar.lz nvim-lspconfig-756549de506bcf9cf9361e87c8b360154b9d7235.tar.xz nvim-lspconfig-756549de506bcf9cf9361e87c8b360154b9d7235.tar.zst nvim-lspconfig-756549de506bcf9cf9361e87c8b360154b9d7235.zip | |
fix(jdtls): update handlers to support 0.5.1 signature (#1336)
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/lspconfig/jdtls.lua | 71 |
1 files changed, 42 insertions, 29 deletions
diff --git a/lua/lspconfig/jdtls.lua b/lua/lspconfig/jdtls.lua index 4205d293..b2f8e39a 100644 --- a/lua/lspconfig/jdtls.lua +++ b/lua/lspconfig/jdtls.lua @@ -38,14 +38,6 @@ local function get_jdtls_config() end end --- Non-standard notification that can be used to display progress -local function on_language_status(_, _, result) - local command = vim.api.nvim_command - command 'echohl ModeMsg' - command(string.format('echo "%s"', result.message)) - command 'echohl None' -end - -- TextDocument version is reported as 0, override with nil so that -- the client doesn't think the document is newer and refuses to update -- See: https://github.com/eclipse/eclipse.jdt.ls/issues/1695 @@ -61,6 +53,44 @@ local function fix_zero_version(workspace_edit) return workspace_edit end +-- Compatibility shim added for breaking changes to the lsp handler signature in nvim-0.5.1 +local function remap_arguments(err, result, ctx) + if vim.fn.has 'nvim-0.5.1' == 1 then + handlers[ctx.method](err, result, ctx) + else + handlers[ctx.method](err, ctx.method, result) + end +end + +local function on_textdocument_codeaction(err, actions, ctx) + for _, action in ipairs(actions) do + -- TODO: (steelsojka) Handle more than one edit? + if action.command == 'java.apply.workspaceEdit' then -- 'action' is Command in java format + action.edit = fix_zero_version(action.edit or action.arguments[1]) + elseif type(action.command) == 'table' and action.command.command == 'java.apply.workspaceEdit' then -- 'action' is CodeAction in java format + action.edit = fix_zero_version(action.edit or action.command.arguments[1]) + end + end + + remap_arguments(err, actions, ctx) +end + +local function on_textdocument_rename(err, workspace_edit, ctx) + remap_arguments(err, fix_zero_version(workspace_edit), ctx) +end + +local function on_workspace_applyedit(err, workspace_edit, ctx) + remap_arguments(err, fix_zero_version(workspace_edit), ctx) +end + +-- Non-standard notification that can be used to display progress +local function on_language_status(_, result) + local command = vim.api.nvim_command + command 'echohl ModeMsg' + command(string.format('echo "%s"', result.message)) + command 'echohl None' +end + local root_files = { -- Single-module projects { @@ -114,27 +144,10 @@ configs[server_name] = { handlers = { -- Due to an invalid protocol implementation in the jdtls we have to conform these to be spec compliant. -- https://github.com/eclipse/eclipse.jdt.ls/issues/376 - ['textDocument/codeAction'] = function(a, b, actions) - for _, action in ipairs(actions) do - -- TODO: (steelsojka) Handle more than one edit? - if action.command == 'java.apply.workspaceEdit' then -- 'action' is Command in java format - action.edit = fix_zero_version(action.edit or action.arguments[1]) - elseif type(action.command) == 'table' and action.command.command == 'java.apply.workspaceEdit' then -- 'action' is CodeAction in java format - action.edit = fix_zero_version(action.edit or action.command.arguments[1]) - end - end - handlers['textDocument/codeAction'](a, b, actions) - end, - - ['textDocument/rename'] = function(a, b, workspace_edit) - handlers['textDocument/rename'](a, b, fix_zero_version(workspace_edit)) - end, - - ['workspace/applyEdit'] = function(a, b, workspace_edit) - handlers['workspace/applyEdit'](a, b, fix_zero_version(workspace_edit)) - end, - - ['language/status'] = vim.schedule_wrap(on_language_status), + ['textDocument/codeAction'] = util.compat_handler(on_textdocument_codeaction), + ['textDocument/rename'] = util.compat_handler(on_textdocument_rename), + ['workspace/applyEdit'] = util.compat_handler(on_workspace_applyedit), + ['language/status'] = util.compat_handler(vim.schedule_wrap(on_language_status)), }, }, docs = { |
