Skip to content

Commit cfa26c3

Browse files
bors[bot]jhgg
andauthored
Merge #10798
10798: ide: show go to for function hover return type r=Veykril a=jhgg I've found myself wanting this... adds to the hover quick go-to for a function's return type: ![image](https://user-images.githubusercontent.com/5489149/142375722-4a385216-494b-45a4-be1c-59664213b8d6.png) This is particularly useful when you are hovering over a function in a long chain, like: ```rust foo.bar().b$0az().some_trait_fn(); ``` where `baz`'s return type is not immediately obvious, but the chain is not long enough to trigger chain inlay hints... i guess I could just select `foo.bar().baz()` too to get the types too... Co-authored-by: Jake Heinz <[email protected]>
2 parents bf8cf09 + 876f44b commit cfa26c3

File tree

2 files changed

+32
-28
lines changed

2 files changed

+32
-28
lines changed

crates/ide/src/hover.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ fn goto_type_action_for_def(db: &RootDatabase, def: Definition) -> Option<HoverA
314314
Definition::Local(it) => it.ty(db),
315315
Definition::GenericParam(hir::GenericParam::ConstParam(it)) => it.ty(db),
316316
Definition::Field(field) => field.ty(db),
317+
Definition::Function(function) => function.ret_type(db),
317318
_ => return None,
318319
};
319320

crates/ide/src/hover/tests.rs

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1718,40 +1718,43 @@ fn test_hover_test_has_action() {
17181718
fn foo_$0test() {}
17191719
"#,
17201720
expect![[r#"
1721-
[
1722-
Reference(
1723-
FilePosition {
1721+
[
1722+
Reference(
1723+
FilePosition {
1724+
file_id: FileId(
1725+
0,
1726+
),
1727+
offset: 11,
1728+
},
1729+
),
1730+
Runnable(
1731+
Runnable {
1732+
use_name_in_title: false,
1733+
nav: NavigationTarget {
17241734
file_id: FileId(
17251735
0,
17261736
),
1727-
offset: 11,
1737+
full_range: 0..24,
1738+
focus_range: 11..19,
1739+
name: "foo_test",
1740+
kind: Function,
17281741
},
1729-
),
1730-
Runnable(
1731-
Runnable {
1732-
use_name_in_title: false,
1733-
nav: NavigationTarget {
1734-
file_id: FileId(
1735-
0,
1736-
),
1737-
full_range: 0..24,
1738-
focus_range: 11..19,
1739-
name: "foo_test",
1740-
kind: Function,
1741-
},
1742-
kind: Test {
1743-
test_id: Path(
1744-
"foo_test",
1745-
),
1746-
attr: TestAttr {
1747-
ignore: false,
1748-
},
1742+
kind: Test {
1743+
test_id: Path(
1744+
"foo_test",
1745+
),
1746+
attr: TestAttr {
1747+
ignore: false,
17491748
},
1750-
cfg: None,
17511749
},
1752-
),
1753-
]
1754-
"#]],
1750+
cfg: None,
1751+
},
1752+
),
1753+
GoToType(
1754+
[],
1755+
),
1756+
]
1757+
"#]],
17551758
);
17561759
}
17571760

0 commit comments

Comments
 (0)