mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-12 05:08:52 +00:00
Merge pull request #18801 from roife/fix-18799
feat: show go-to-type-def actions for subst when hovering
This commit is contained in:
commit
6ccbb2d194
3 changed files with 57 additions and 3 deletions
|
@ -429,7 +429,7 @@ pub(crate) fn hover_for_definition(
|
||||||
¬able_traits,
|
¬able_traits,
|
||||||
macro_arm,
|
macro_arm,
|
||||||
hovered_definition,
|
hovered_definition,
|
||||||
subst_types,
|
subst_types.as_ref(),
|
||||||
config,
|
config,
|
||||||
edition,
|
edition,
|
||||||
);
|
);
|
||||||
|
@ -439,7 +439,7 @@ pub(crate) fn hover_for_definition(
|
||||||
show_fn_references_action(sema.db, def),
|
show_fn_references_action(sema.db, def),
|
||||||
show_implementations_action(sema.db, def),
|
show_implementations_action(sema.db, def),
|
||||||
runnable_action(sema, def, file_id),
|
runnable_action(sema, def, file_id),
|
||||||
goto_type_action_for_def(sema.db, def, ¬able_traits, edition),
|
goto_type_action_for_def(sema.db, def, ¬able_traits, subst_types, edition),
|
||||||
]
|
]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.flatten()
|
.flatten()
|
||||||
|
@ -531,6 +531,7 @@ fn goto_type_action_for_def(
|
||||||
db: &RootDatabase,
|
db: &RootDatabase,
|
||||||
def: Definition,
|
def: Definition,
|
||||||
notable_traits: &[(hir::Trait, Vec<(Option<hir::Type>, hir::Name)>)],
|
notable_traits: &[(hir::Trait, Vec<(Option<hir::Type>, hir::Name)>)],
|
||||||
|
subst_types: Option<Vec<(hir::Symbol, hir::Type)>>,
|
||||||
edition: Edition,
|
edition: Edition,
|
||||||
) -> Option<HoverAction> {
|
) -> Option<HoverAction> {
|
||||||
let mut targets: Vec<hir::ModuleDef> = Vec::new();
|
let mut targets: Vec<hir::ModuleDef> = Vec::new();
|
||||||
|
@ -568,6 +569,12 @@ fn goto_type_action_for_def(
|
||||||
walk_and_push_ty(db, &ty, &mut push_new_def);
|
walk_and_push_ty(db, &ty, &mut push_new_def);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(subst_types) = subst_types {
|
||||||
|
for (_, ty) in subst_types {
|
||||||
|
walk_and_push_ty(db, &ty, &mut push_new_def);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
HoverAction::goto_type_from_targets(db, targets, edition)
|
HoverAction::goto_type_from_targets(db, targets, edition)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -432,7 +432,7 @@ pub(super) fn definition(
|
||||||
notable_traits: &[(Trait, Vec<(Option<Type>, Name)>)],
|
notable_traits: &[(Trait, Vec<(Option<Type>, Name)>)],
|
||||||
macro_arm: Option<u32>,
|
macro_arm: Option<u32>,
|
||||||
hovered_definition: bool,
|
hovered_definition: bool,
|
||||||
subst_types: Option<Vec<(Symbol, Type)>>,
|
subst_types: Option<&Vec<(Symbol, Type)>>,
|
||||||
config: &HoverConfig,
|
config: &HoverConfig,
|
||||||
edition: Edition,
|
edition: Edition,
|
||||||
) -> Markup {
|
) -> Markup {
|
||||||
|
|
|
@ -2322,6 +2322,53 @@ fn foo(Foo { b$0ar }: &Foo) {}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_hover_show_type_def_for_subst() {
|
||||||
|
check_actions(
|
||||||
|
r#"
|
||||||
|
fn f<T>(t: T) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
struct S;
|
||||||
|
|
||||||
|
fn test() {
|
||||||
|
let a = S;
|
||||||
|
f$0(a);
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
[
|
||||||
|
Reference(
|
||||||
|
FilePositionWrapper {
|
||||||
|
file_id: FileId(
|
||||||
|
0,
|
||||||
|
),
|
||||||
|
offset: 3,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
GoToType(
|
||||||
|
[
|
||||||
|
HoverGotoTypeData {
|
||||||
|
mod_path: "ra_test_fixture::S",
|
||||||
|
nav: NavigationTarget {
|
||||||
|
file_id: FileId(
|
||||||
|
0,
|
||||||
|
),
|
||||||
|
full_range: 20..29,
|
||||||
|
focus_range: 27..28,
|
||||||
|
name: "S",
|
||||||
|
kind: Struct,
|
||||||
|
description: "struct S",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_hover_non_ascii_space_doc() {
|
fn test_hover_non_ascii_space_doc() {
|
||||||
check(
|
check(
|
||||||
|
|
Loading…
Reference in a new issue