diff options
Diffstat (limited to 'crates/ide/src/hover.rs')
-rw-r--r-- | crates/ide/src/hover.rs | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs index c43089476..5f9edb476 100644 --- a/crates/ide/src/hover.rs +++ b/crates/ide/src/hover.rs | |||
@@ -82,6 +82,8 @@ pub struct HoverResult { | |||
82 | // | 82 | // |
83 | // Shows additional information, like type of an expression or documentation for definition when "focusing" code. | 83 | // Shows additional information, like type of an expression or documentation for definition when "focusing" code. |
84 | // Focusing is usually hovering with a mouse, but can also be triggered with a shortcut. | 84 | // Focusing is usually hovering with a mouse, but can also be triggered with a shortcut. |
85 | // | ||
86 | // image::https://user-images.githubusercontent.com/48062697/113020658-b5f98b80-917a-11eb-9f88-3dbc27320c95.gif[] | ||
85 | pub(crate) fn hover( | 87 | pub(crate) fn hover( |
86 | db: &RootDatabase, | 88 | db: &RootDatabase, |
87 | position: FilePosition, | 89 | position: FilePosition, |
@@ -195,7 +197,7 @@ fn show_implementations_action(db: &RootDatabase, def: Definition) -> Option<Hov | |||
195 | let adt = match def { | 197 | let adt = match def { |
196 | Definition::ModuleDef(ModuleDef::Trait(it)) => return it.try_to_nav(db).map(to_action), | 198 | Definition::ModuleDef(ModuleDef::Trait(it)) => return it.try_to_nav(db).map(to_action), |
197 | Definition::ModuleDef(ModuleDef::Adt(it)) => Some(it), | 199 | Definition::ModuleDef(ModuleDef::Adt(it)) => Some(it), |
198 | Definition::SelfType(it) => it.target_ty(db).as_adt(), | 200 | Definition::SelfType(it) => it.self_ty(db).as_adt(), |
199 | _ => None, | 201 | _ => None, |
200 | }?; | 202 | }?; |
201 | adt.try_to_nav(db).map(to_action) | 203 | adt.try_to_nav(db).map(to_action) |
@@ -318,7 +320,7 @@ fn definition_owner_name(db: &RootDatabase, def: &Definition) -> Option<String> | |||
318 | Definition::ModuleDef(md) => match md { | 320 | Definition::ModuleDef(md) => match md { |
319 | ModuleDef::Function(f) => match f.as_assoc_item(db)?.container(db) { | 321 | ModuleDef::Function(f) => match f.as_assoc_item(db)?.container(db) { |
320 | AssocItemContainer::Trait(t) => Some(t.name(db)), | 322 | AssocItemContainer::Trait(t) => Some(t.name(db)), |
321 | AssocItemContainer::Impl(i) => i.target_ty(db).as_adt().map(|adt| adt.name(db)), | 323 | AssocItemContainer::Impl(i) => i.self_ty(db).as_adt().map(|adt| adt.name(db)), |
322 | }, | 324 | }, |
323 | ModuleDef::Variant(e) => Some(e.parent_enum(db).name(db)), | 325 | ModuleDef::Variant(e) => Some(e.parent_enum(db).name(db)), |
324 | _ => None, | 326 | _ => None, |
@@ -376,7 +378,7 @@ fn hover_for_definition( | |||
376 | }, | 378 | }, |
377 | Definition::Local(it) => hover_for_local(it, db), | 379 | Definition::Local(it) => hover_for_local(it, db), |
378 | Definition::SelfType(impl_def) => { | 380 | Definition::SelfType(impl_def) => { |
379 | impl_def.target_ty(db).as_adt().and_then(|adt| from_hir_fmt(db, adt, mod_path)) | 381 | impl_def.self_ty(db).as_adt().and_then(|adt| from_hir_fmt(db, adt, mod_path)) |
380 | } | 382 | } |
381 | Definition::GenericParam(it) => from_hir_fmt(db, it, None), | 383 | Definition::GenericParam(it) => from_hir_fmt(db, it, None), |
382 | Definition::Label(it) => Some(Markup::fenced_block(&it.name(db))), | 384 | Definition::Label(it) => Some(Markup::fenced_block(&it.name(db))), |
@@ -470,6 +472,7 @@ fn find_std_module(famous_defs: &FamousDefs, name: &str) -> Option<hir::Module> | |||
470 | 472 | ||
471 | fn pick_best(tokens: TokenAtOffset<SyntaxToken>) -> Option<SyntaxToken> { | 473 | fn pick_best(tokens: TokenAtOffset<SyntaxToken>) -> Option<SyntaxToken> { |
472 | return tokens.max_by_key(priority); | 474 | return tokens.max_by_key(priority); |
475 | |||
473 | fn priority(n: &SyntaxToken) -> usize { | 476 | fn priority(n: &SyntaxToken) -> usize { |
474 | match n.kind() { | 477 | match n.kind() { |
475 | IDENT | INT_NUMBER | LIFETIME_IDENT | T![self] | T![super] | T![crate] => 3, | 478 | IDENT | INT_NUMBER | LIFETIME_IDENT | T![self] | T![super] | T![crate] => 3, |
@@ -1235,6 +1238,37 @@ fn f() { fo$0o!(); } | |||
1235 | } | 1238 | } |
1236 | 1239 | ||
1237 | #[test] | 1240 | #[test] |
1241 | fn test_hover_macro2_invocation() { | ||
1242 | check( | ||
1243 | r#" | ||
1244 | /// foo bar | ||
1245 | /// | ||
1246 | /// foo bar baz | ||
1247 | macro foo() {} | ||
1248 | |||
1249 | fn f() { fo$0o!(); } | ||
1250 | "#, | ||
1251 | expect![[r#" | ||
1252 | *foo* | ||
1253 | |||
1254 | ```rust | ||
1255 | test | ||
1256 | ``` | ||
1257 | |||
1258 | ```rust | ||
1259 | macro foo | ||
1260 | ``` | ||
1261 | |||
1262 | --- | ||
1263 | |||
1264 | foo bar | ||
1265 | |||
1266 | foo bar baz | ||
1267 | "#]], | ||
1268 | ) | ||
1269 | } | ||
1270 | |||
1271 | #[test] | ||
1238 | fn test_hover_tuple_field() { | 1272 | fn test_hover_tuple_field() { |
1239 | check( | 1273 | check( |
1240 | r#"struct TS(String, i32$0);"#, | 1274 | r#"struct TS(String, i32$0);"#, |