Skip to content

Commit 6ccbb2d

Browse files
authored
Merge pull request #18801 from roife/fix-18799
feat: show go-to-type-def actions for subst when hovering
2 parents 1c6b838 + edaf62e commit 6ccbb2d

File tree

3 files changed

+57
-3
lines changed

3 files changed

+57
-3
lines changed

crates/ide/src/hover.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ pub(crate) fn hover_for_definition(
429429
&notable_traits,
430430
macro_arm,
431431
hovered_definition,
432-
subst_types,
432+
subst_types.as_ref(),
433433
config,
434434
edition,
435435
);
@@ -439,7 +439,7 @@ pub(crate) fn hover_for_definition(
439439
show_fn_references_action(sema.db, def),
440440
show_implementations_action(sema.db, def),
441441
runnable_action(sema, def, file_id),
442-
goto_type_action_for_def(sema.db, def, &notable_traits, edition),
442+
goto_type_action_for_def(sema.db, def, &notable_traits, subst_types, edition),
443443
]
444444
.into_iter()
445445
.flatten()
@@ -531,6 +531,7 @@ fn goto_type_action_for_def(
531531
db: &RootDatabase,
532532
def: Definition,
533533
notable_traits: &[(hir::Trait, Vec<(Option<hir::Type>, hir::Name)>)],
534+
subst_types: Option<Vec<(hir::Symbol, hir::Type)>>,
534535
edition: Edition,
535536
) -> Option<HoverAction> {
536537
let mut targets: Vec<hir::ModuleDef> = Vec::new();
@@ -568,6 +569,12 @@ fn goto_type_action_for_def(
568569
walk_and_push_ty(db, &ty, &mut push_new_def);
569570
}
570571

572+
if let Some(subst_types) = subst_types {
573+
for (_, ty) in subst_types {
574+
walk_and_push_ty(db, &ty, &mut push_new_def);
575+
}
576+
}
577+
571578
HoverAction::goto_type_from_targets(db, targets, edition)
572579
}
573580

crates/ide/src/hover/render.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ pub(super) fn definition(
432432
notable_traits: &[(Trait, Vec<(Option<Type>, Name)>)],
433433
macro_arm: Option<u32>,
434434
hovered_definition: bool,
435-
subst_types: Option<Vec<(Symbol, Type)>>,
435+
subst_types: Option<&Vec<(Symbol, Type)>>,
436436
config: &HoverConfig,
437437
edition: Edition,
438438
) -> Markup {

crates/ide/src/hover/tests.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2322,6 +2322,53 @@ fn foo(Foo { b$0ar }: &Foo) {}
23222322
)
23232323
}
23242324

2325+
#[test]
2326+
fn test_hover_show_type_def_for_subst() {
2327+
check_actions(
2328+
r#"
2329+
fn f<T>(t: T) {
2330+
2331+
}
2332+
2333+
struct S;
2334+
2335+
fn test() {
2336+
let a = S;
2337+
f$0(a);
2338+
}
2339+
"#,
2340+
expect![[r#"
2341+
[
2342+
Reference(
2343+
FilePositionWrapper {
2344+
file_id: FileId(
2345+
0,
2346+
),
2347+
offset: 3,
2348+
},
2349+
),
2350+
GoToType(
2351+
[
2352+
HoverGotoTypeData {
2353+
mod_path: "ra_test_fixture::S",
2354+
nav: NavigationTarget {
2355+
file_id: FileId(
2356+
0,
2357+
),
2358+
full_range: 20..29,
2359+
focus_range: 27..28,
2360+
name: "S",
2361+
kind: Struct,
2362+
description: "struct S",
2363+
},
2364+
},
2365+
],
2366+
),
2367+
]
2368+
"#]],
2369+
);
2370+
}
2371+
23252372
#[test]
23262373
fn test_hover_non_ascii_space_doc() {
23272374
check(

0 commit comments

Comments
 (0)