aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_ide_api/src/hover.rs29
1 files changed, 23 insertions, 6 deletions
diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs
index ad00abe49..df877c324 100644
--- a/crates/ra_ide_api/src/hover.rs
+++ b/crates/ra_ide_api/src/hover.rs
@@ -95,6 +95,8 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn
95 if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(file.syntax(), position.offset) { 95 if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(file.syntax(), position.offset) {
96 let analyzer = hir::SourceAnalyzer::new(db, position.file_id, name_ref.syntax(), None); 96 let analyzer = hir::SourceAnalyzer::new(db, position.file_id, name_ref.syntax(), None);
97 97
98 let mut no_fallback = false;
99
98 match classify_name_ref(db, &analyzer, name_ref) { 100 match classify_name_ref(db, &analyzer, name_ref) {
99 Some(Method(it)) => res.extend(from_def_source(db, it)), 101 Some(Method(it)) => res.extend(from_def_source(db, it)),
100 Some(Macro(it)) => { 102 Some(Macro(it)) => {
@@ -142,11 +144,9 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn
142 }) 144 })
143 } 145 }
144 } 146 }
145 Some(Pat(_)) => { 147 Some(Pat(_)) | Some(SelfParam(_)) => {
146 res.extend(None); 148 // Hover for these shows type names
147 } 149 no_fallback = true;
148 Some(SelfParam(_)) => {
149 res.extend(None);
150 } 150 }
151 Some(GenericParam(_)) => { 151 Some(GenericParam(_)) => {
152 // FIXME: Hover for generic param 152 // FIXME: Hover for generic param
@@ -154,7 +154,7 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn
154 None => {} 154 None => {}
155 } 155 }
156 156
157 if res.is_empty() { 157 if res.is_empty() && !no_fallback {
158 // Fallback index based approach: 158 // Fallback index based approach:
159 let symbols = crate::symbol_index::index_resolve(db, name_ref); 159 let symbols = crate::symbol_index::index_resolve(db, name_ref);
160 for sym in symbols { 160 for sym in symbols {
@@ -675,4 +675,21 @@ fn func(foo: i32) { if true { <|>foo; }; }
675 assert_eq!(trim_markup_opt(hover.info.first()), Some("enum Thing")); 675 assert_eq!(trim_markup_opt(hover.info.first()), Some("enum Thing"));
676 assert_eq!(hover.info.is_exact(), true); 676 assert_eq!(hover.info.is_exact(), true);
677 } 677 }
678
679 #[test]
680 fn test_hover_shadowing_pat() {
681 let (analysis, position) = single_file_with_position(
682 "
683 fn x() {}
684
685 fn y() {
686 let x = 0i32;
687 x<|>;
688 }
689 ",
690 );
691 let hover = analysis.hover(position).unwrap().unwrap();
692 assert_eq!(trim_markup_opt(hover.info.first()), Some("i32"));
693 assert_eq!(hover.info.is_exact(), true);
694 }
678} 695}