diff --git a/clients/lsp-rust.el b/clients/lsp-rust.el index 29a88ee730c..7ff04f8f982 100644 --- a/clients/lsp-rust.el +++ b/clients/lsp-rust.el @@ -295,7 +295,7 @@ PARAMS progress report notification data." (lsp-workspace-status nil workspace) (lsp-workspace-status (format "%s - %s" title (or message? "")) workspace)))) -(cl-defmethod lsp-execute-command (_server (_command (eql rls.run)) params) +(lsp-defun lsp-rust--rls-run ((&Command :arguments? params)) (-let* (((&rls:Cmd :env :binary :args :cwd) (lsp-seq-first params)) (default-directory (or cwd (lsp-workspace-root) default-directory) )) (compile @@ -635,6 +635,11 @@ them with `crate` or the crate name they refer to." (lsp-defun lsp-rust--analyzer-run-single ((&Command :arguments?)) (lsp-rust-analyzer-run (lsp-seq-first arguments?))) +(lsp-defun lsp-rust--analyzer-show-references + ((&Command :title :arguments? [_uri _filepos references])) + (lsp-show-xrefs (lsp--locations-to-xref-items references) nil + (s-contains-p "reference" title))) + (lsp-register-client (make-lsp-client :new-connection (lsp-stdio-connection @@ -648,7 +653,8 @@ them with `crate` or the crate name they refer to." :priority (if (eq lsp-rust-server 'rust-analyzer) 1 -1) :initialization-options 'lsp-rust-analyzer--make-init-options :notification-handlers (ht<-alist lsp-rust-notification-handlers) - :action-handlers (ht ("rust-analyzer.runSingle" #'lsp-rust--analyzer-run-single)) + :action-handlers (ht ("rust-analyzer.runSingle" #'lsp-rust--analyzer-run-single) + ("rust-analyzer.showReferences" #'lsp-rust--analyzer-show-references)) :library-folders-fn (lambda (_workspace) lsp-rust-library-directories) :after-open-fn (lambda () (when lsp-rust-analyzer-server-display-inlay-hints diff --git a/lsp-lens.el b/lsp-lens.el index 16d5fa2a91c..f1c0299f7ff 100644 --- a/lsp-lens.el +++ b/lsp-lens.el @@ -144,19 +144,14 @@ See `lsp-lens--schedule-refresh' for details." (define-key [mouse-1] (lsp-lens--create-interactive-command command)))) (defun lsp-lens--create-interactive-command (command?) - "Create an interactive COMMAND? for the lens." - (let ((server-id (->> (lsp-workspaces) - (cl-first) - (or lsp--cur-workspace) - (lsp--workspace-client) - (lsp--client-server-id)))) - (if (functionp (lsp:command-command command?)) - (lsp:command-command command?) - (lambda () - (interactive) - (lsp-execute-command server-id - (intern (lsp:command-command command?)) - (lsp:command-arguments? command?)))))) + "Create an interactive COMMAND? for the lens. +COMMAND? shall be an `&Command' (e.g. `&CodeLens' :command?) and +mustn't be nil." + (if (functionp (lsp:command-command command?)) + (lsp:command-command command?) + (lambda () + (interactive) + (lsp--execute-command command?)))) (defun lsp-lens--display (lenses) "Show LENSES." diff --git a/lsp-mode.el b/lsp-mode.el index e2859f3c083..91057d9d160 100755 --- a/lsp-mode.el +++ b/lsp-mode.el @@ -969,7 +969,8 @@ 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.") + "Ask SERVER to execute COMMAND with ARGUMENTS." + (declare (obsolete "use `make-lsp-client' with :action-handlers instead." "7.1.0"))) (defun lsp-elt (sequence n) "Return Nth element of SEQUENCE or nil if N is out of range." @@ -5208,9 +5209,18 @@ It will filter by KIND if non nil." (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 + (with-no-warnings + (lsp-execute-command server-id (intern command) arguments?)) + (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. @@ -5740,7 +5750,7 @@ REFERENCES? t when METHOD returns references." (lsp-request "workspace/executeCommand" params))) (defun lsp--send-execute-command (command &optional args) - "Execute workspace COMMAND with ARGS showing error if command is not mapped client-side." + "Create and send a 'workspace/executeCommand' message having command COMMAND and optional ARGS." (condition-case-unless-debug err (lsp-workspace-command-execute command args) (error