Skip to content

Commit 44e5986

Browse files
committed
Support `lsp-execute-command'
`lsp-execute-command' now works as an extension point again, but a deprecation warning is shown if it is used to handle a command. To implement this, leverage `cl-no-applicable-method': call `lsp-execute-command' first, and then, if there is no implementation, go trough the handler hash tables as usual.
1 parent f8a85ec commit 44e5986

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

lsp-mode.el

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,6 +1088,9 @@ calling `remove-overlays'.")
10881088

10891089
(defvar-local lsp--virtual-buffer-point-max nil)
10901090

1091+
(cl-defgeneric lsp-execute-command (server command arguments)
1092+
"Ask SERVER to execute COMMAND with ARGUMENTS.")
1093+
10911094
(defun lsp-elt (sequence n)
10921095
"Return Nth element of SEQUENCE or nil if N is out of range."
10931096
(cond
@@ -5168,9 +5171,18 @@ It will show up only if current point has signature help."
51685171

51695172
(lsp-defun lsp--execute-command ((action &as &Command :command :arguments?))
51705173
"Parse and execute a code ACTION represented as a Command LSP type."
5171-
(-if-let* ((action-handler (lsp--find-action-handler command)))
5172-
(funcall action-handler action)
5173-
(lsp--send-execute-command command arguments?)))
5174+
(let ((server-id (->> (lsp-workspaces)
5175+
(cl-first)
5176+
(or lsp--cur-workspace)
5177+
(lsp--workspace-client)
5178+
(lsp--client-server-id))))
5179+
(condition-case nil
5180+
(prog1 (lsp-execute-command server-id (intern command) arguments?)
5181+
(lsp--warn "`lsp-execute-command' is deprecated"))
5182+
(cl-no-applicable-method
5183+
(if-let ((action-handler (lsp--find-action-handler command)))
5184+
(funcall action-handler action)
5185+
(lsp--send-execute-command command arguments?))))))
51745186

51755187
(lsp-defun lsp-execute-code-action ((action &as &CodeAction :command? :edit?))
51765188
"Execute code action ACTION.

0 commit comments

Comments
 (0)