diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-11-28 23:38:18 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-11-28 23:38:18 +0000 |
commit | c8a2ff6ecc8e45c7e1420e01d52c8b7a315140e6 (patch) | |
tree | b4bd205a863938211d19ef860ca90025badc1453 /crates/ide | |
parent | a6f26ded0037a3efb5625ac3482a2f4ec9eb01a3 (diff) | |
parent | ee8afff71486a59334a812b69b8ebe0c4c2afba9 (diff) |
Merge #6664
6664: Show type of self param on hover r=jonas-schievink a=Veykril
Show the type of `self` when hovering the token in a `SelfParam`.
Co-authored-by: Lukas Wirth <[email protected]>
Diffstat (limited to 'crates/ide')
-rw-r--r-- | crates/ide/src/hover.rs | 46 |
1 files changed, 43 insertions, 3 deletions
diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs index 832192881..94ad800a0 100644 --- a/crates/ide/src/hover.rs +++ b/crates/ide/src/hover.rs | |||
@@ -139,14 +139,17 @@ pub(crate) fn hover( | |||
139 | } | 139 | } |
140 | } | 140 | } |
141 | 141 | ||
142 | let node = token | 142 | let node = token.ancestors().find(|n| { |
143 | .ancestors() | 143 | ast::Expr::can_cast(n.kind()) |
144 | .find(|n| ast::Expr::cast(n.clone()).is_some() || ast::Pat::cast(n.clone()).is_some())?; | 144 | || ast::Pat::can_cast(n.kind()) |
145 | || ast::SelfParam::can_cast(n.kind()) | ||
146 | })?; | ||
145 | 147 | ||
146 | let ty = match_ast! { | 148 | let ty = match_ast! { |
147 | match node { | 149 | match node { |
148 | ast::Expr(it) => sema.type_of_expr(&it)?, | 150 | ast::Expr(it) => sema.type_of_expr(&it)?, |
149 | ast::Pat(it) => sema.type_of_pat(&it)?, | 151 | ast::Pat(it) => sema.type_of_pat(&it)?, |
152 | ast::SelfParam(self_param) => sema.type_of_self(&self_param)?, | ||
150 | // If this node is a MACRO_CALL, it means that `descend_into_macros` failed to resolve. | 153 | // If this node is a MACRO_CALL, it means that `descend_into_macros` failed to resolve. |
151 | // (e.g expanding a builtin macro). So we give up here. | 154 | // (e.g expanding a builtin macro). So we give up here. |
152 | ast::MacroCall(_it) => return None, | 155 | ast::MacroCall(_it) => return None, |
@@ -3282,4 +3285,41 @@ fn main() { | |||
3282 | "#]], | 3285 | "#]], |
3283 | ); | 3286 | ); |
3284 | } | 3287 | } |
3288 | |||
3289 | #[test] | ||
3290 | fn hover_self_param_shows_type() { | ||
3291 | check( | ||
3292 | r#" | ||
3293 | struct Foo {} | ||
3294 | impl Foo { | ||
3295 | fn bar(&sel<|>f) {} | ||
3296 | } | ||
3297 | "#, | ||
3298 | expect![[r#" | ||
3299 | *&self* | ||
3300 | ```rust | ||
3301 | &Foo | ||
3302 | ``` | ||
3303 | "#]], | ||
3304 | ); | ||
3305 | } | ||
3306 | |||
3307 | #[test] | ||
3308 | fn hover_self_param_shows_type_for_arbitrary_self_type() { | ||
3309 | check( | ||
3310 | r#" | ||
3311 | struct Arc<T>(T); | ||
3312 | struct Foo {} | ||
3313 | impl Foo { | ||
3314 | fn bar(sel<|>f: Arc<Foo>) {} | ||
3315 | } | ||
3316 | "#, | ||
3317 | expect![[r#" | ||
3318 | *self: Arc<Foo>* | ||
3319 | ```rust | ||
3320 | Arc<Foo> | ||
3321 | ``` | ||
3322 | "#]], | ||
3323 | ); | ||
3324 | } | ||
3285 | } | 3325 | } |