From c66a789a045c3c521620af73c1f06314fbe315bb Mon Sep 17 00:00:00 2001 From: uHOOCCOOHu Date: Tue, 10 Sep 2019 13:33:02 +0800 Subject: Show macro definition in hover text --- crates/ra_ide_api/src/hover.rs | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs index 1981e62d3..4b7847de8 100644 --- a/crates/ra_ide_api/src/hover.rs +++ b/crates/ra_ide_api/src/hover.rs @@ -12,8 +12,8 @@ use ra_syntax::{ use crate::{ db::RootDatabase, display::{ - description_from_symbol, docs_from_symbol, rust_code_markup, rust_code_markup_with_doc, - ShortLabel, + description_from_symbol, docs_from_symbol, macro_label, rust_code_markup, + rust_code_markup_with_doc, ShortLabel, }, name_ref_kind::{classify_name_ref, NameRefKind::*}, FilePosition, FileRange, RangeInfo, @@ -108,7 +108,7 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option res.extend(from_def_source(db, it)), Some(Macro(it)) => { let src = it.source(db); - res.extend(hover_text(src.ast.doc_comment_text(), None)); + res.extend(hover_text(src.ast.doc_comment_text(), Some(macro_label(&src.ast)))); } Some(FieldAccess(it)) => { let src = it.source(db); @@ -700,4 +700,22 @@ fn func(foo: i32) { if true { <|>foo; }; } assert_eq!(trim_markup_opt(hover.info.first()), Some("i32")); assert_eq!(hover.info.is_exact(), true); } + + #[test] + fn test_hover_macro_invocation() { + let (analysis, position) = single_file_with_position( + " + macro_rules! foo { + () => {} + } + + fn f() { + fo<|>o!(); + } + ", + ); + let hover = analysis.hover(position).unwrap().unwrap(); + assert_eq!(trim_markup_opt(hover.info.first()), Some("macro_rules! foo")); + assert_eq!(hover.info.is_exact(), true); + } } -- cgit v1.2.3