Skip to content

Commit 1eb9c53

Browse files
committed
lsp-rust: support rust-analyzer.showReference lens
Add a rust-analyzer specific :action-handler for the showReference lens, which leverages `lsp-show-xrefs'. Refactor: eliminate `lsp-execute-command', because it caused the :title to be lost, which is needed to distinguish between the "references" or "implementations" variants of that lens. Defining a new `lsp-interface' to destructure "rust-analyzer.showReference" was impossible, as the former doesn't support destructuring lists (the :arguments? paramter is a special, 3-element list.).
1 parent f306b1a commit 1eb9c53

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

clients/lsp-rust.el

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ PARAMS progress report notification data."
290290
(lsp-workspace-status nil workspace)
291291
(lsp-workspace-status (format "%s - %s" title (or message? "")) workspace))))
292292

293-
(cl-defmethod lsp-execute-command (_server (_command (eql rls.run)) params)
293+
(lsp-defun lsp-rust--rls-run ((&Command :arguments? params))
294294
(-let* (((&rls:Cmd :env :binary :args :cwd) (lsp-seq-first params))
295295
(default-directory (or cwd (lsp-workspace-root) default-directory) ))
296296
(compile
@@ -585,6 +585,13 @@ The command should include `--message=format=json` or similar option."
585585
(lsp-defun lsp-rust--analyzer-run-single ((&Command :arguments?))
586586
(lsp-rust-analyzer-run (lsp-seq-first arguments?)))
587587

588+
;; `lsp-interface' is unsuitable for ShowReference destructuring, as that code
589+
;; action yields an array of three elements, not a map.
590+
(lsp-defun lsp-rust--analyzer-show-references
591+
((&Command :title :arguments? [_uri _filepos references]))
592+
(lsp-show-xrefs (lsp--locations-to-xref-items references) nil
593+
(s-contains-p "reference" title)))
594+
588595
(lsp-register-client
589596
(make-lsp-client
590597
:new-connection (lsp-stdio-connection
@@ -598,7 +605,8 @@ The command should include `--message=format=json` or similar option."
598605
:priority (if (eq lsp-rust-server 'rust-analyzer) 1 -1)
599606
:initialization-options 'lsp-rust-analyzer--make-init-options
600607
:notification-handlers (ht<-alist lsp-rust-notification-handlers)
601-
:action-handlers (ht ("rust-analyzer.runSingle" #'lsp-rust--analyzer-run-single))
608+
:action-handlers (ht ("rust-analyzer.runSingle" #'lsp-rust--analyzer-run-single)
609+
("rust-analyzer.showReferences" #'lsp-rust--analyzer-show-references))
602610
:library-folders-fn (lambda (_workspace) lsp-rust-library-directories)
603611
:after-open-fn (lambda ()
604612
(when lsp-rust-analyzer-server-display-inlay-hints

lsp-lens.el

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,7 @@ BUFFER-MODIFIED? determines whether the buffer is modified or not."
154154
(lsp:command-command command?)
155155
(lambda ()
156156
(interactive)
157-
(lsp-execute-command server-id
158-
(intern (lsp:command-command command?))
159-
(lsp:command-arguments? command?))))))
157+
(lsp--execute-command command?)))))
160158

161159
(defun lsp-lens--display (lenses)
162160
"Show LENSES."

lsp-mode.el

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,9 +1085,6 @@ calling `remove-overlays'.")
10851085

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

1088-
(cl-defgeneric lsp-execute-command (server command arguments)
1089-
"Ask SERVER to execute COMMAND with ARGUMENTS.")
1090-
10911088
(defun lsp-elt (sequence n)
10921089
"Return Nth element of SEQUENCE or nil if N is out of range."
10931090
(cond
@@ -5772,11 +5769,6 @@ REFERENCES? t when METHOD returns references."
57725769

57735770
(defalias 'lsp-feature? 'lsp--find-workspaces-for)
57745771

5775-
(cl-defmethod lsp-execute-command (_server command arguments)
5776-
"Dispatch COMMAND execution."
5777-
(lsp--execute-command (lsp-make-command :command (symbol-name command)
5778-
:arguments? arguments)))
5779-
57805772
(defun lsp--send-execute-command (command &optional args)
57815773
"Create and send a 'workspace/executeCommand' message having command COMMAND and optional ARGS."
57825774
(let ((params (if args

0 commit comments

Comments
 (0)