From acafbd66f80f79a1b9f9ce181eb3bc22d0ebbf72 Mon Sep 17 00:00:00 2001 From: Shotaro Yamada Date: Tue, 11 Jun 2019 23:32:33 +0900 Subject: Fix hover for pat that shadows items --- crates/ra_ide_api/src/hover.rs | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) (limited to 'crates/ra_ide_api') 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(file.syntax(), position.offset) { let analyzer = hir::SourceAnalyzer::new(db, position.file_id, name_ref.syntax(), None); + let mut no_fallback = false; + match classify_name_ref(db, &analyzer, name_ref) { Some(Method(it)) => { let it = it.source(db).1; @@ -190,11 +192,9 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option { - res.extend(None); - } - Some(SelfParam(_)) => { - res.extend(None); + Some(Pat(_)) | Some(SelfParam(_)) => { + // Hover for these shows type names + no_fallback = true; } Some(GenericParam(_)) => { // FIXME: Hover for generic param @@ -202,7 +202,7 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option {} } - if res.is_empty() { + if res.is_empty() && !no_fallback { // Fallback index based approach: let symbols = crate::symbol_index::index_resolve(db, name_ref); for sym in symbols { @@ -714,4 +714,21 @@ fn func(foo: i32) { if true { <|>foo; }; } assert_eq!(trim_markup_opt(hover.info.first()), Some("enum Thing")); assert_eq!(hover.info.is_exact(), true); } + + #[test] + fn test_hover_shadowing_pat() { + let (analysis, position) = single_file_with_position( + " + fn x() {} + + fn y() { + let x = 0i32; + x<|>; + } + ", + ); + let hover = analysis.hover(position).unwrap().unwrap(); + assert_eq!(trim_markup_opt(hover.info.first()), Some("i32")); + assert_eq!(hover.info.is_exact(), true); + } } -- cgit v1.2.3