Skip to content

Commit

Permalink
rust-analyzer client: extract signature in hover content (#4465)
Browse files Browse the repository at this point in the history
* rust-analyzer client: extract signature in hover content

* require
  • Loading branch information
blahgeek authored May 31, 2024
1 parent 556a4ed commit acad044
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions clients/lsp-rust.el
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
(require 'ht)
(require 'dash)
(require 'lsp-semantic-tokens)
(require 's)

(defgroup lsp-rust nil
"LSP support for Rust, using Rust Language Server or rust-analyzer."
Expand Down Expand Up @@ -1764,6 +1765,16 @@ https://github.com/rust-lang/rust-analyzer/blob/master/docs/dev/lsp-extensions.m
:download-server-fn (lambda (_client callback error-callback _update?)
(lsp-package-ensure 'rust-analyzer callback error-callback))))

(cl-defmethod lsp-clients-extract-signature-on-hover (contents (_server-id (eql rust-analyzer)))
"Extract first non-comment line from rust-analyzer's hover CONTENTS.
The first line of the hover contents is usally about memory layout or notable
traits starting with //, with the actual signature follows."
(let* ((lines (s-lines (s-trim (lsp--render-element contents))))
(non-comment-lines (--filter (not (s-prefix? "//" it)) lines)))
(if non-comment-lines
(car non-comment-lines)
(car lines))))

(lsp-consistency-check lsp-rust)

(provide 'lsp-rust)
Expand Down

0 comments on commit acad044

Please sign in to comment.