diff options
Diffstat (limited to 'crates/ra_ide_api/src')
-rw-r--r-- | crates/ra_ide_api/src/hover.rs | 29 |
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 fbabeb194..bc8e8fd14 100644 --- a/crates/ra_ide_api/src/hover.rs +++ b/crates/ra_ide_api/src/hover.rs | |||
@@ -94,6 +94,8 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn | |||
94 | if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(file.syntax(), position.offset) { | 94 | if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(file.syntax(), position.offset) { |
95 | let analyzer = hir::SourceAnalyzer::new(db, position.file_id, name_ref.syntax(), None); | 95 | let analyzer = hir::SourceAnalyzer::new(db, position.file_id, name_ref.syntax(), None); |
96 | 96 | ||
97 | let mut no_fallback = false; | ||
98 | |||
97 | match classify_name_ref(db, &analyzer, name_ref) { | 99 | match classify_name_ref(db, &analyzer, name_ref) { |
98 | Some(Method(it)) => { | 100 | Some(Method(it)) => { |
99 | let it = it.source(db).1; | 101 | let it = it.source(db).1; |
@@ -190,11 +192,9 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn | |||
190 | } | 192 | } |
191 | } | 193 | } |
192 | } | 194 | } |
193 | Some(Pat(_)) => { | 195 | Some(Pat(_)) | Some(SelfParam(_)) => { |
194 | res.extend(None); | 196 | // Hover for these shows type names |
195 | } | 197 | no_fallback = true; |
196 | Some(SelfParam(_)) => { | ||
197 | res.extend(None); | ||
198 | } | 198 | } |
199 | Some(GenericParam(_)) => { | 199 | Some(GenericParam(_)) => { |
200 | // FIXME: Hover for generic param | 200 | // FIXME: Hover for generic param |
@@ -202,7 +202,7 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn | |||
202 | None => {} | 202 | None => {} |
203 | } | 203 | } |
204 | 204 | ||
205 | if res.is_empty() { | 205 | if res.is_empty() && !no_fallback { |
206 | // Fallback index based approach: | 206 | // Fallback index based approach: |
207 | let symbols = crate::symbol_index::index_resolve(db, name_ref); | 207 | let symbols = crate::symbol_index::index_resolve(db, name_ref); |
208 | for sym in symbols { | 208 | for sym in symbols { |
@@ -714,4 +714,21 @@ fn func(foo: i32) { if true { <|>foo; }; } | |||
714 | assert_eq!(trim_markup_opt(hover.info.first()), Some("enum Thing")); | 714 | assert_eq!(trim_markup_opt(hover.info.first()), Some("enum Thing")); |
715 | assert_eq!(hover.info.is_exact(), true); | 715 | assert_eq!(hover.info.is_exact(), true); |
716 | } | 716 | } |
717 | |||
718 | #[test] | ||
719 | fn test_hover_shadowing_pat() { | ||
720 | let (analysis, position) = single_file_with_position( | ||
721 | " | ||
722 | fn x() {} | ||
723 | |||
724 | fn y() { | ||
725 | let x = 0i32; | ||
726 | x<|>; | ||
727 | } | ||
728 | ", | ||
729 | ); | ||
730 | let hover = analysis.hover(position).unwrap().unwrap(); | ||
731 | assert_eq!(trim_markup_opt(hover.info.first()), Some("i32")); | ||
732 | assert_eq!(hover.info.is_exact(), true); | ||
733 | } | ||
717 | } | 734 | } |