From 4f4de4d80e1df43d58e5e21677fca4c63676664d Mon Sep 17 00:00:00 2001 From: Mathias Fussenegger Date: Mon, 29 Jan 2024 18:39:31 +0100 Subject: [PATCH] Ensure source.generate.* capabilities are always set `tbl_deep_extend('keep', ...)` doesn't merge lists, and neovim already sets some code action literals. This prevented hashCode/toString code actions from showing up. --- lua/jdtls/setup.lua | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/lua/jdtls/setup.lua b/lua/jdtls/setup.lua index 9e4f50c..8adde5c 100644 --- a/lua/jdtls/setup.lua +++ b/lua/jdtls/setup.lua @@ -293,22 +293,37 @@ function M.start_or_attach(config, opts, start_opts) config.handlers['language/status'] = config.handlers['language/status'] or status_callback config.handlers['workspace/configuration'] = config.handlers['workspace/configuration'] or configuration_handler local capabilities = vim.tbl_deep_extend('keep', config.capabilities or {}, lsp.protocol.make_client_capabilities()) + local extra_code_action_literals = { + "source.generate.toString", + "source.generate.hashCodeEquals", + "source.organizeImports", + } + local code_action_literals = vim.tbl_get( + capabilities, + "textDocument", + "codeAction", + "codeActionLiteralSupport", + "codeActionKind", + "valueSet" + ) or {} + for _, extra_literal in ipairs(extra_code_action_literals) do + if not vim.tbl_contains(code_action_literals, extra_literal) then + table.insert(code_action_literals, extra_literal) + end + end local extra_capabilities = { textDocument = { codeAction = { codeActionLiteralSupport = { codeActionKind = { - valueSet = { - "source.generate.toString", - "source.generate.hashCodeEquals", - "source.organizeImports", - }; + valueSet = code_action_literals }; }; } } } - config.capabilities = vim.tbl_deep_extend('keep', capabilities, extra_capabilities) + config.capabilities = vim.tbl_deep_extend('force', capabilities, extra_capabilities) + config.init_options = config.init_options or {} config.init_options.extendedClientCapabilities = ( config.init_options.extendedClientCapabilities or vim.deepcopy(M.extendedClientCapabilities)