@@ -72,28 +72,21 @@ pub(crate) fn highlight_related(
72
72
T ! [ break ] | T ! [ loop ] | T ! [ while ] | T ! [ continue ] if config. break_points => {
73
73
highlight_break_points ( token)
74
74
}
75
- T ! [ |] if config. closure_captures => highlight_closure_captures (
76
- sema,
77
- token. parent_ancestors ( ) . nth ( 1 ) . and_then ( ast:: ClosureExpr :: cast) ?,
78
- file_id,
79
- ) ,
80
- T ! [ move] if config. closure_captures => highlight_closure_captures (
81
- sema,
82
- token. parent ( ) . and_then ( ast:: ClosureExpr :: cast) ?,
83
- file_id,
84
- ) ,
75
+ T ! [ |] if config. closure_captures => highlight_closure_captures ( sema, token, file_id) ,
76
+ T ! [ move] if config. closure_captures => highlight_closure_captures ( sema, token, file_id) ,
85
77
_ if config. references => highlight_references ( sema, & syntax, token, file_id) ,
86
78
_ => None ,
87
79
}
88
80
}
89
81
90
82
fn highlight_closure_captures (
91
83
sema : & Semantics < ' _ , RootDatabase > ,
92
- node : ast :: ClosureExpr ,
84
+ token : SyntaxToken ,
93
85
file_id : FileId ,
94
86
) -> Option < Vec < HighlightedRange > > {
95
- let search_range = node. body ( ) ?. syntax ( ) . text_range ( ) ;
96
- let ty = & sema. type_of_expr ( & node. into ( ) ) ?. original ;
87
+ let closure = token. parent_ancestors ( ) . take ( 2 ) . find_map ( ast:: ClosureExpr :: cast) ?;
88
+ let search_range = closure. body ( ) ?. syntax ( ) . text_range ( ) ;
89
+ let ty = & sema. type_of_expr ( & closure. into ( ) ) ?. original ;
97
90
let c = ty. as_closure ( ) ?;
98
91
Some (
99
92
c. captured_items ( sema. db )
0 commit comments