Skip to content

Commit

Permalink
Support `lsp-execute-command'
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
nbfalcon committed Nov 20, 2020
1 parent f8a85ec commit 44e5986
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions lsp-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -1088,6 +1088,9 @@ calling `remove-overlays'.")

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

(cl-defgeneric lsp-execute-command (server command arguments)
"Ask SERVER to execute COMMAND with ARGUMENTS.")

(defun lsp-elt (sequence n)
"Return Nth element of SEQUENCE or nil if N is out of range."
(cond
Expand Down Expand Up @@ -5168,9 +5171,18 @@ It will show up only if current point has signature help."

(lsp-defun lsp--execute-command ((action &as &Command :command :arguments?))
"Parse and execute a code ACTION represented as a Command LSP type."
(-if-let* ((action-handler (lsp--find-action-handler command)))
(funcall action-handler action)
(lsp--send-execute-command command arguments?)))
(let ((server-id (->> (lsp-workspaces)
(cl-first)
(or lsp--cur-workspace)
(lsp--workspace-client)
(lsp--client-server-id))))
(condition-case nil
(prog1 (lsp-execute-command server-id (intern command) arguments?)
(lsp--warn "`lsp-execute-command' is deprecated"))
(cl-no-applicable-method
(if-let ((action-handler (lsp--find-action-handler command)))
(funcall action-handler action)
(lsp--send-execute-command command arguments?))))))

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

0 comments on commit 44e5986

Please sign in to comment.