Skip to content

Commit dddb162

Browse files
nbfalconyyoncho
authored andcommitted
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 4e766bc commit dddb162

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
@@ -968,6 +968,9 @@ calling `remove-overlays'.")
968968

969969
(defvar-local lsp--virtual-buffer-point-max nil)
970970

971+
(cl-defgeneric lsp-execute-command (server command arguments)
972+
"Ask SERVER to execute COMMAND with ARGUMENTS.")
973+
971974
(defun lsp-elt (sequence n)
972975
"Return Nth element of SEQUENCE or nil if N is out of range."
973976
(cond
@@ -5205,9 +5208,18 @@ It will filter by KIND if non nil."
52055208

52065209
(lsp-defun lsp--execute-command ((action &as &Command :command :arguments?))
52075210
"Parse and execute a code ACTION represented as a Command LSP type."
5208-
(-if-let* ((action-handler (lsp--find-action-handler command)))
5209-
(funcall action-handler action)
5210-
(lsp--send-execute-command command arguments?)))
5211+
(let ((server-id (->> (lsp-workspaces)
5212+
(cl-first)
5213+
(or lsp--cur-workspace)
5214+
(lsp--workspace-client)
5215+
(lsp--client-server-id))))
5216+
(condition-case nil
5217+
(prog1 (lsp-execute-command server-id (intern command) arguments?)
5218+
(lsp--warn "`lsp-execute-command' is deprecated"))
5219+
(cl-no-applicable-method
5220+
(if-let ((action-handler (lsp--find-action-handler command)))
5221+
(funcall action-handler action)
5222+
(lsp--send-execute-command command arguments?))))))
52115223

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

0 commit comments

Comments
 (0)