Skip to content

Commit acad044

Browse files
authored
rust-analyzer client: extract signature in hover content (#4465)
* rust-analyzer client: extract signature in hover content * require
1 parent 556a4ed commit acad044

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

clients/lsp-rust.el

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
(require 'ht)
2929
(require 'dash)
3030
(require 'lsp-semantic-tokens)
31+
(require 's)
3132

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

1768+
(cl-defmethod lsp-clients-extract-signature-on-hover (contents (_server-id (eql rust-analyzer)))
1769+
"Extract first non-comment line from rust-analyzer's hover CONTENTS.
1770+
The first line of the hover contents is usally about memory layout or notable
1771+
traits starting with //, with the actual signature follows."
1772+
(let* ((lines (s-lines (s-trim (lsp--render-element contents))))
1773+
(non-comment-lines (--filter (not (s-prefix? "//" it)) lines)))
1774+
(if non-comment-lines
1775+
(car non-comment-lines)
1776+
(car lines))))
1777+
17671778
(lsp-consistency-check lsp-rust)
17681779

17691780
(provide 'lsp-rust)

0 commit comments

Comments
 (0)