From 5fb075c3dcb7d3912fac342589de852ac73df66c Mon Sep 17 00:00:00 2001 From: Ryosuke Takahashi Date: Wed, 16 Oct 2024 23:36:49 +0900 Subject: [PATCH 1/2] fix: respect user config and server capabilities --- lua/cmp_nvim_lsp/source.lua | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lua/cmp_nvim_lsp/source.lua b/lua/cmp_nvim_lsp/source.lua index 43ccac1..e0a0533 100644 --- a/lua/cmp_nvim_lsp/source.lua +++ b/lua/cmp_nvim_lsp/source.lua @@ -106,9 +106,7 @@ source.execute = function(self, completion_item, callback) return callback() end - self:_request('workspace/executeCommand', completion_item.command, function(_, _) - callback() - end) + self.client:_exec_cmd(completion_item.command, nil, callback, nil) end ---Get object path. From 2a4db9333c0960d82c46de5ce2660a80a25a4c10 Mon Sep 17 00:00:00 2001 From: Ryosuke Takahashi Date: Thu, 17 Oct 2024 17:00:52 +0900 Subject: [PATCH 2/2] fix: `callback` was not called unless workspace/executeCommand request is made --- lua/cmp_nvim_lsp/source.lua | 38 +++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/lua/cmp_nvim_lsp/source.lua b/lua/cmp_nvim_lsp/source.lua index e0a0533..05e6e78 100644 --- a/lua/cmp_nvim_lsp/source.lua +++ b/lua/cmp_nvim_lsp/source.lua @@ -102,11 +102,45 @@ source.execute = function(self, completion_item, callback) end -- completion_item has no command. - if not completion_item.command then + local command = completion_item.command + if not command then return callback() end - self.client:_exec_cmd(completion_item.command, nil, callback, nil) + -- The logic below is taken from the following and is slightly modified. + -- https://github.com/neovim/neovim/blob/f72dc2b4c805f309f23aff62b3e7ba7b71a554d2/runtime/lua/vim/lsp/client.lua#L864-L905 + local bufnr = vim.api.nvim_get_current_buf() + local f = self.client.commands[command.command] or vim.lsp.commands[command.command] + if f then + f(command, { bufnr = bufnr, client_id = self.client.id }) + callback() + return + end + + local command_provider = self.client.server_capabilities.executeCommandProvider + local commands = type(command_provider) == 'table' and command_provider.commands or {} + if not vim.list_contains(commands, command.command) then + vim.notify_once( + string.format( + 'cmp_nvim_lsp: Language server `%s` does not support command `%s`. This command may require a client extension.', + self.client.name, + command.command + ), + vim.log.levels.WARN + ) + callback() + return + end + + -- Not using command directly to exclude extra properties, + -- see https://github.com/python-lsp/python-lsp-server/issues/146 + local params = { + command = command.command, + arguments = command.arguments, + } + self.client.request(vim.lsp.protocol.Methods.workspace_executeCommand, params, function() + callback() + end, bufnr) end ---Get object path.