mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 05:45:12 +00:00
Show macro definition in hover text
This commit is contained in:
parent
7de9537ccc
commit
c66a789a04
1 changed files with 21 additions and 3 deletions
|
@ -12,8 +12,8 @@ use ra_syntax::{
|
||||||
use crate::{
|
use crate::{
|
||||||
db::RootDatabase,
|
db::RootDatabase,
|
||||||
display::{
|
display::{
|
||||||
description_from_symbol, docs_from_symbol, rust_code_markup, rust_code_markup_with_doc,
|
description_from_symbol, docs_from_symbol, macro_label, rust_code_markup,
|
||||||
ShortLabel,
|
rust_code_markup_with_doc, ShortLabel,
|
||||||
},
|
},
|
||||||
name_ref_kind::{classify_name_ref, NameRefKind::*},
|
name_ref_kind::{classify_name_ref, NameRefKind::*},
|
||||||
FilePosition, FileRange, RangeInfo,
|
FilePosition, FileRange, RangeInfo,
|
||||||
|
@ -108,7 +108,7 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn
|
||||||
Some(Method(it)) => res.extend(from_def_source(db, it)),
|
Some(Method(it)) => res.extend(from_def_source(db, it)),
|
||||||
Some(Macro(it)) => {
|
Some(Macro(it)) => {
|
||||||
let src = it.source(db);
|
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)) => {
|
Some(FieldAccess(it)) => {
|
||||||
let src = it.source(db);
|
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!(trim_markup_opt(hover.info.first()), Some("i32"));
|
||||||
assert_eq!(hover.info.is_exact(), true);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue