]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
Correct HandleCodeAction behavior for CodeAction
authorAndrei Tihonovschi <andrew@bw.at.home>
Sun, 30 Oct 2022 18:05:29 +0000 (20:05 +0200)
committerAndrei Tihonovschi <andrew@bw.at.home>
Sun, 30 Oct 2022 18:05:29 +0000 (20:05 +0200)
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

index 63d1cae72a50f8e18e60db7b15d4af8deb441e41..02bf7cd8ce7e6433b73f4f39fa9fd9f030ccbe3d 100644 (file)
@@ -10,15 +10,20 @@ export def HandleCodeAction(lspserver: dict<any>, selAction: dict<any>)
   # 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