diff options
author | Felicián Németh <felician.nemeth@gmail.com> | 2024-07-24 15:15:27 +0200 |
---|---|---|
committer | Felicián Németh <felician.nemeth@gmail.com> | 2024-07-30 19:46:15 +0200 |
commit | b0898b11224422af207001faa3849269ae7259d4 (patch) | |
tree | eae9b819943e4fcb322bbd192bdb81c5527432f1 | |
parent | 194806de6e49e898ac782db0d66594ae617a536d (diff) |
Implement client command "rust-analyzer.showReferences"
* eglot-x.el (eglot-x-client-commands): Add showReferences.
(eglot-x--show-references): New defun, dispatched from ...
(eglot-x-execute-command): ... here.
-rw-r--r-- | eglot-x.el | 36 |
1 files changed, 26 insertions, 10 deletions
@@ -217,13 +217,13 @@ the debugging process a tiny bit easier." :type 'boolean) (defcustom eglot-x-client-commands - (list "rust-analyzer.gotoLocation" "rust-analyzer.rename" - "editor.action.rename") + (list "rust-analyzer.showReferences" "rust-analyzer.gotoLocation" + "rust-analyzer.rename" "editor.action.rename") "List of commands the LSP client supports and advertises to the server." :type '(set ;;(const "rust-analyzer.runSingle") ;;(const "rust-analyzer.debugSingle") - ;;(const "rust-analyzer.showReferences") + (const "rust-analyzer.showReferences") (const "rust-analyzer.gotoLocation") ;;(const "rust-analyzer.triggerParameterHints") (const "rust-analyzer.rename") @@ -686,7 +686,6 @@ See `eglot-x-enable-refs'." ;; Client Commands (See client_commands() in rust-analyzer/src/config.rs) ;; - rust-analyzer.runSingle ;; - rust-analyzer.debugSingle -;; - rust-analyzer.showReferences ;; - rust-analyzer.triggerParameterHints ;; CodeAction Groups ;; Configuration in initializationOptions @@ -2133,13 +2132,30 @@ It relys on a rust-analyzer LSP extension." :takeFocus t :selection targetSelectionRange)) +(defun eglot-x--show-references (server args) + "Execute rust-analyzer's showReferences client command." + ;; args is (filename location references) + (let ((xrefs + (eglot--collecting-xrefs (collect) + (mapc + (lambda (item) + (let* ((uri (plist-get item :uri)) + (range (plist-get item :range)) + (name (file-name-nondirectory uri)) + (eglot--cached-server server)) + (collect (eglot--xref-make-match name uri range)))) + (append (caddr args) nil)))) + (xref-show-xrefs-function xref-show-definitions-function)) + (xref-show-xrefs xrefs nil))) + (defun eglot-x-execute-command (server command) - (pcase (plist-get command :command) - ("rust-analyzer.gotoLocation" - (apply #'eglot-x--goto-location server - (car (append (plist-get command :arguments) nil)))) - ("rust-analyzer.rename" (call-interactively #'eglot-rename)) - (_ (eglot--request server :workspace/executeCommand command)))) + (let ((args (append (plist-get command :arguments) nil))) + (pcase (plist-get command :command) + ("rust-analyzer.gotoLocation" + (apply #'eglot-x--goto-location server (car args))) + ("rust-analyzer.rename" (call-interactively #'eglot-rename)) + ("rust-analyzer.showReferences" (eglot-x--show-references server args)) + (_ (eglot--request server :workspace/executeCommand command))))) (cl-defmethod eglot-execute :around (server action) "Execute ACTION locally if possible, otherwise ask SERVER to execute it." |