From: Andrei Tihonovschi Date: Sun, 30 Oct 2022 18:05:29 +0000 (+0200) Subject: Correct HandleCodeAction behavior for CodeAction X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=089ab59aab2e5a2e6b445d0a6c5e3a1c23e4f2f7;p=vim-lsp.git 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. --- 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