From 089ab59aab2e5a2e6b445d0a6c5e3a1c23e4f2f7 Mon Sep 17 00:00:00 2001 From: Andrei Tihonovschi Date: Sun, 30 Oct 2022 20:05:29 +0200 Subject: [PATCH] Correct HandleCodeAction behavior for CodeAction Both the CodeAction and Command interfaces contain the 'command' member but these should be handled differently for them. Corrected the 'HandleCodeAction' method to correctly handle these. --- autoload/lsp/codeaction.vim | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/autoload/lsp/codeaction.vim b/autoload/lsp/codeaction.vim index 63d1cae..02bf7cd 100644 --- a/autoload/lsp/codeaction.vim +++ b/autoload/lsp/codeaction.vim @@ -10,15 +10,20 @@ export def HandleCodeAction(lspserver: dict, selAction: dict) # textDocument/codeAction can return either Command[] or CodeAction[]. # If it is a CodeAction, it can have either an edit, a command or both. # Edits should be executed first. - if selAction->has_key('edit') || selAction->has_key('command') + # Both Command and CodeAction interfaces has 'command' member + # so we should check 'command' type - for Command it will be 'string' + if selAction->has_key('edit') + || (selAction->has_key('command') && selAction.command->type() == v:t_dict) + # selAction is a CodeAction instance, apply edit and command if selAction->has_key('edit') # apply edit first textedit.ApplyWorkspaceEdit(selAction.edit) endif if selAction->has_key('command') - lspserver.executeCommand(selAction) + lspserver.executeCommand(selAction.command) endif else + # selAction is a Command instance, apply it directly lspserver.executeCommand(selAction) endif enddef -- 2.48.1