diff options
-rw-r--r-- | crates/ra_ide/src/display/function_signature.rs | 19 | ||||
-rw-r--r-- | crates/ra_ide/src/inlay_hints.rs | 23 | ||||
-rw-r--r-- | editors/emacs/rust-analyzer.el | 19 |
3 files changed, 38 insertions, 23 deletions
diff --git a/crates/ra_ide/src/display/function_signature.rs b/crates/ra_ide/src/display/function_signature.rs index ddc53a52b..1e4a472b4 100644 --- a/crates/ra_ide/src/display/function_signature.rs +++ b/crates/ra_ide/src/display/function_signature.rs | |||
@@ -169,9 +169,22 @@ impl From<&'_ ast::FnDef> for FunctionSignature { | |||
169 | res.push(self_param.syntax().text().to_string()) | 169 | res.push(self_param.syntax().text().to_string()) |
170 | } | 170 | } |
171 | 171 | ||
172 | res.extend(param_list.params().map(|param| { | 172 | res.extend( |
173 | param.pat().map(|pat| pat.syntax().text().to_string()).unwrap_or_default() | 173 | param_list |
174 | })); | 174 | .params() |
175 | .map(|param| { | ||
176 | Some( | ||
177 | param | ||
178 | .pat()? | ||
179 | .syntax() | ||
180 | .descendants() | ||
181 | .find_map(ast::Name::cast)? | ||
182 | .text() | ||
183 | .to_string(), | ||
184 | ) | ||
185 | }) | ||
186 | .map(|param| param.unwrap_or_default()), | ||
187 | ); | ||
175 | } | 188 | } |
176 | res | 189 | res |
177 | } | 190 | } |
diff --git a/crates/ra_ide/src/inlay_hints.rs b/crates/ra_ide/src/inlay_hints.rs index 1b631c7cd..236557541 100644 --- a/crates/ra_ide/src/inlay_hints.rs +++ b/crates/ra_ide/src/inlay_hints.rs | |||
@@ -116,7 +116,7 @@ fn get_param_name_hints( | |||
116 | let hints = parameters | 116 | let hints = parameters |
117 | .zip(args) | 117 | .zip(args) |
118 | .filter_map(|(param, arg)| { | 118 | .filter_map(|(param, arg)| { |
119 | if arg.syntax().kind() == SyntaxKind::LITERAL { | 119 | if arg.syntax().kind() == SyntaxKind::LITERAL && !param.is_empty() { |
120 | Some((arg.syntax().text_range(), param)) | 120 | Some((arg.syntax().text_range(), param)) |
121 | } else { | 121 | } else { |
122 | None | 122 | None |
@@ -683,12 +683,12 @@ fn main() { | |||
683 | struct Test {} | 683 | struct Test {} |
684 | 684 | ||
685 | impl Test { | 685 | impl Test { |
686 | fn method(&self, param: i32) -> i32 { | 686 | fn method(&self, mut param: i32) -> i32 { |
687 | param * 2 | 687 | param * 2 |
688 | } | 688 | } |
689 | } | 689 | } |
690 | 690 | ||
691 | fn test_func(foo: i32, bar: i32, msg: &str, _: i32, last: i32) -> i32 { | 691 | fn test_func(mut foo: i32, bar: i32, msg: &str, _: i32, last: i32) -> i32 { |
692 | foo + bar | 692 | foo + bar |
693 | } | 693 | } |
694 | 694 | ||
@@ -704,37 +704,32 @@ fn main() { | |||
704 | assert_debug_snapshot!(analysis.inlay_hints(file_id, None).unwrap(), @r###" | 704 | assert_debug_snapshot!(analysis.inlay_hints(file_id, None).unwrap(), @r###" |
705 | [ | 705 | [ |
706 | InlayHint { | 706 | InlayHint { |
707 | range: [207; 218), | 707 | range: [215; 226), |
708 | kind: TypeHint, | 708 | kind: TypeHint, |
709 | label: "i32", | 709 | label: "i32", |
710 | }, | 710 | }, |
711 | InlayHint { | 711 | InlayHint { |
712 | range: [251; 252), | 712 | range: [259; 260), |
713 | kind: ParameterHint, | 713 | kind: ParameterHint, |
714 | label: "foo", | 714 | label: "foo", |
715 | }, | 715 | }, |
716 | InlayHint { | 716 | InlayHint { |
717 | range: [254; 255), | 717 | range: [262; 263), |
718 | kind: ParameterHint, | 718 | kind: ParameterHint, |
719 | label: "bar", | 719 | label: "bar", |
720 | }, | 720 | }, |
721 | InlayHint { | 721 | InlayHint { |
722 | range: [257; 264), | 722 | range: [265; 272), |
723 | kind: ParameterHint, | 723 | kind: ParameterHint, |
724 | label: "msg", | 724 | label: "msg", |
725 | }, | 725 | }, |
726 | InlayHint { | 726 | InlayHint { |
727 | range: [266; 267), | 727 | range: [331; 334), |
728 | kind: ParameterHint, | ||
729 | label: "_", | ||
730 | }, | ||
731 | InlayHint { | ||
732 | range: [323; 326), | ||
733 | kind: ParameterHint, | 728 | kind: ParameterHint, |
734 | label: "param", | 729 | label: "param", |
735 | }, | 730 | }, |
736 | InlayHint { | 731 | InlayHint { |
737 | range: [350; 354), | 732 | range: [358; 362), |
738 | kind: ParameterHint, | 733 | kind: ParameterHint, |
739 | label: "param", | 734 | label: "param", |
740 | }, | 735 | }, |
diff --git a/editors/emacs/rust-analyzer.el b/editors/emacs/rust-analyzer.el index 8ba98bf61..06db4f15f 100644 --- a/editors/emacs/rust-analyzer.el +++ b/editors/emacs/rust-analyzer.el | |||
@@ -210,9 +210,9 @@ | |||
210 | ;; inlay hints | 210 | ;; inlay hints |
211 | (defun rust-analyzer--update-inlay-hints (buffer) | 211 | (defun rust-analyzer--update-inlay-hints (buffer) |
212 | (if (and (rust-analyzer--initialized?) (eq buffer (current-buffer))) | 212 | (if (and (rust-analyzer--initialized?) (eq buffer (current-buffer))) |
213 | (lsp-send-request-async | 213 | (lsp-request-async |
214 | (lsp-make-request "rust-analyzer/inlayHints" | 214 | "rust-analyzer/inlayHints" |
215 | (list :textDocument (lsp--text-document-identifier))) | 215 | (list :textDocument (lsp--text-document-identifier)) |
216 | (lambda (res) | 216 | (lambda (res) |
217 | (remove-overlays (point-min) (point-max) 'rust-analyzer--inlay-hint t) | 217 | (remove-overlays (point-min) (point-max) 'rust-analyzer--inlay-hint t) |
218 | (dolist (hint res) | 218 | (dolist (hint res) |
@@ -221,9 +221,16 @@ | |||
221 | (overlay (make-overlay beg end))) | 221 | (overlay (make-overlay beg end))) |
222 | (overlay-put overlay 'rust-analyzer--inlay-hint t) | 222 | (overlay-put overlay 'rust-analyzer--inlay-hint t) |
223 | (overlay-put overlay 'evaporate t) | 223 | (overlay-put overlay 'evaporate t) |
224 | (overlay-put overlay 'after-string (propertize (concat ": " label) | 224 | (cond |
225 | 'font-lock-face 'font-lock-comment-face))))) | 225 | ((string= kind "TypeHint") |
226 | 'tick)) | 226 | (overlay-put overlay 'after-string (propertize (concat ": " label) |
227 | 'font-lock-face 'font-lock-comment-face))) | ||
228 | ((string= kind "ParameterHint") | ||
229 | (overlay-put overlay 'before-string (propertize (concat label ": ") | ||
230 | 'font-lock-face 'font-lock-comment-face))) | ||
231 | ) | ||
232 | ))) | ||
233 | :mode 'tick)) | ||
227 | nil) | 234 | nil) |
228 | 235 | ||
229 | (defvar-local rust-analyzer--inlay-hints-timer nil) | 236 | (defvar-local rust-analyzer--inlay-hints-timer nil) |