aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-02-17 13:17:15 +0000
committerGitHub <[email protected]>2021-02-17 13:17:15 +0000
commit056601b41fbc5208cae5d996ec7fd18526d79e41 (patch)
tree74ac5ee88df768a9b3011ac43a8bd26b074f35c0
parent5cd7a0f2c5a7948dcd6b1838e1497c560d5c65a1 (diff)
parent51dda8ea8e4e64b3ee5ed6971d3182f6b3df987f (diff)
Merge #7705
7705: Show hover info of the definition of ConstReference patterns instead of its type r=Veykril a=Veykril Closes #7671 bors r+ Co-authored-by: Lukas Wirth <[email protected]>
-rw-r--r--crates/ide/src/hover.rs40
1 files changed, 38 insertions, 2 deletions
diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs
index 00745238a..69b828f47 100644
--- a/crates/ide/src/hover.rs
+++ b/crates/ide/src/hover.rs
@@ -2,8 +2,8 @@ use hir::{
2 Adt, AsAssocItem, AssocItemContainer, FieldSource, GenericParam, HasAttrs, HasSource, 2 Adt, AsAssocItem, AssocItemContainer, FieldSource, GenericParam, HasAttrs, HasSource,
3 HirDisplay, Module, ModuleDef, ModuleSource, Semantics, 3 HirDisplay, Module, ModuleDef, ModuleSource, Semantics,
4}; 4};
5use ide_db::base_db::SourceDatabase;
6use ide_db::{ 5use ide_db::{
6 base_db::SourceDatabase,
7 defs::{Definition, NameClass, NameRefClass}, 7 defs::{Definition, NameClass, NameRefClass},
8 RootDatabase, 8 RootDatabase,
9}; 9};
@@ -94,7 +94,12 @@ pub(crate) fn hover(
94 let node = token.parent(); 94 let node = token.parent();
95 let definition = match_ast! { 95 let definition = match_ast! {
96 match node { 96 match node {
97 ast::Name(name) => NameClass::classify(&sema, &name).and_then(|d| d.defined(sema.db)), 97 // we don't use NameClass::referenced_or_defined here as we do not want to resolve
98 // field pattern shorthands to their definition
99 ast::Name(name) => NameClass::classify(&sema, &name).and_then(|class| match class {
100 NameClass::ConstReference(def) => Some(def),
101 def => def.defined(sema.db),
102 }),
98 ast::NameRef(name_ref) => NameRefClass::classify(&sema, &name_ref).map(|d| d.referenced(sema.db)), 103 ast::NameRef(name_ref) => NameRefClass::classify(&sema, &name_ref).map(|d| d.referenced(sema.db)),
99 ast::Lifetime(lifetime) => NameClass::classify_lifetime(&sema, &lifetime) 104 ast::Lifetime(lifetime) => NameClass::classify_lifetime(&sema, &lifetime)
100 .map_or_else(|| NameRefClass::classify_lifetime(&sema, &lifetime).map(|d| d.referenced(sema.db)), |d| d.defined(sema.db)), 105 .map_or_else(|| NameRefClass::classify_lifetime(&sema, &lifetime).map(|d| d.referenced(sema.db)), |d| d.defined(sema.db)),
@@ -3446,6 +3451,37 @@ impl<const LEN: usize> Foo<LEN$0> {}
3446 } 3451 }
3447 3452
3448 #[test] 3453 #[test]
3454 fn hover_const_pat() {
3455 check(
3456 r#"
3457/// This is a doc
3458const FOO: usize = 3;
3459fn foo() {
3460 match 5 {
3461 FOO$0 => (),
3462 _ => ()
3463 }
3464}
3465"#,
3466 expect![[r#"
3467 *FOO*
3468
3469 ```rust
3470 test
3471 ```
3472
3473 ```rust
3474 const FOO: usize = 3
3475 ```
3476
3477 ---
3478
3479 This is a doc
3480 "#]],
3481 );
3482 }
3483
3484 #[test]
3449 fn hover_mod_def() { 3485 fn hover_mod_def() {
3450 check( 3486 check(
3451 r#" 3487 r#"