File tree Expand file tree Collapse file tree 1 file changed +43
-3
lines changed Expand file tree Collapse file tree 1 file changed +43
-3
lines changed Original file line number Diff line number Diff line change @@ -139,14 +139,17 @@ pub(crate) fn hover(
139139 }
140140 }
141141
142- let node = token
143- . ancestors ( )
144- . find ( |n| ast:: Expr :: cast ( n. clone ( ) ) . is_some ( ) || ast:: Pat :: cast ( n. clone ( ) ) . is_some ( ) ) ?;
142+ let node = token. ancestors ( ) . find ( |n| {
143+ ast:: Expr :: can_cast ( n. kind ( ) )
144+ || ast:: Pat :: can_cast ( n. kind ( ) )
145+ || ast:: SelfParam :: can_cast ( n. kind ( ) )
146+ } ) ?;
145147
146148 let ty = match_ast ! {
147149 match node {
148150 ast:: Expr ( it) => sema. type_of_expr( & it) ?,
149151 ast:: Pat ( it) => sema. type_of_pat( & it) ?,
152+ ast:: SelfParam ( self_param) => sema. type_of_self( & self_param) ?,
150153 // If this node is a MACRO_CALL, it means that `descend_into_macros` failed to resolve.
151154 // (e.g expanding a builtin macro). So we give up here.
152155 ast:: MacroCall ( _it) => return None ,
@@ -3282,4 +3285,41 @@ fn main() {
32823285 "# ] ] ,
32833286 ) ;
32843287 }
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+ }
32853325}
You can’t perform that action at this time.
0 commit comments