Merge #1394
1394: Fix hover for pat that shadows items r=matklad a=sinkuu ```rust fn x() {} fn y() { let x = 0i32; x; // hover on `x` is expected to be `i32`, but the actual result was `fn x()` } ``` This was because: if [`res.is_empty()`](656a0fa9f9/crates/ra_ide_api/src/hover.rs (L205)
), it fallbacks to "index based approach" and adds `fn x()` to `res`, which makes [`res.extend(type_of)` below](656a0fa9f9/crates/ra_ide_api/src/hover.rs (L260-L266)
) not happen. Co-authored-by: Shotaro Yamada <sinkuu@sinkuu.xyz>
This commit is contained in:
commit
98020ef2f3
1 changed files with 23 additions and 6 deletions
|
@ -95,6 +95,8 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn
|
|||
if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(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)) => res.extend(from_def_source(db, it)),
|
||||
Some(Macro(it)) => {
|
||||
|
@ -142,11 +144,9 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn
|
|||
})
|
||||
}
|
||||
}
|
||||
Some(Pat(_)) => {
|
||||
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
|
||||
|
@ -154,7 +154,7 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn
|
|||
None => {}
|
||||
}
|
||||
|
||||
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 {
|
||||
|
@ -675,4 +675,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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue