@@ -119,7 +119,7 @@ pub(crate) fn hover(
119
119
let edition =
120
120
sema. attach_first_edition ( file_id) . map ( |it| it. edition ( ) ) . unwrap_or ( Edition :: CURRENT ) ;
121
121
let mut res = if range. is_empty ( ) {
122
- hover_simple ( sema, FilePosition { file_id, offset : range. start ( ) } , file, config, edition)
122
+ hover_offset ( sema, FilePosition { file_id, offset : range. start ( ) } , file, config, edition)
123
123
} else {
124
124
hover_ranged ( sema, frange, file, config, edition)
125
125
} ?;
@@ -131,7 +131,7 @@ pub(crate) fn hover(
131
131
}
132
132
133
133
#[ allow( clippy:: field_reassign_with_default) ]
134
- fn hover_simple (
134
+ fn hover_offset (
135
135
sema : & Semantics < ' _ , RootDatabase > ,
136
136
FilePosition { file_id, offset } : FilePosition ,
137
137
file : SyntaxNode ,
@@ -186,26 +186,23 @@ fn hover_simple(
186
186
let text = original_token. text ( ) ;
187
187
let ident_kind = kind. is_any_identifier ( ) ;
188
188
189
- descended. sort_by_key ( |tok| {
189
+ descended. sort_by_cached_key ( |tok| {
190
190
let tok_kind = tok. kind ( ) ;
191
191
192
192
let exact_same_kind = tok_kind == kind;
193
193
let both_idents = exact_same_kind || ( tok_kind. is_any_identifier ( ) && ident_kind) ;
194
194
let same_text = tok. text ( ) == text;
195
195
// anything that mapped into a token tree has likely no semantic information
196
196
let no_tt_parent = tok. parent ( ) . map_or ( false , |it| it. kind ( ) != TOKEN_TREE ) ;
197
- ( both_idents as usize )
197
+ ! ( ( both_idents as usize )
198
198
| ( ( exact_same_kind as usize ) << 1 )
199
199
| ( ( same_text as usize ) << 2 )
200
- | ( ( no_tt_parent as usize ) << 3 )
200
+ | ( ( no_tt_parent as usize ) << 3 ) )
201
201
} ) ;
202
202
203
203
let mut res = vec ! [ ] ;
204
- // let mut merge_result = |next: HoverResult| {
205
- // res.markup = Markup::from(format!("{}\n---\n{}", res.markup, next.markup));
206
- // res.actions.extend(next.actions);
207
- // };
208
204
for token in descended {
205
+ let is_same_kind = token. kind ( ) == kind;
209
206
let lint_hover = ( || {
210
207
// FIXME: Definition should include known lints and the like instead of having this special case here
211
208
let attr = token. parent_ancestors ( ) . find_map ( ast:: Attr :: cast) ?;
@@ -273,9 +270,14 @@ fn hover_simple(
273
270
continue ;
274
271
}
275
272
let keywords = || render:: keyword ( sema, config, & token, edition) ;
276
- let underscore = || render:: underscore ( sema, config, & token, edition) ;
273
+ let underscore = || {
274
+ if !is_same_kind {
275
+ return None ;
276
+ }
277
+ render:: underscore ( sema, config, & token, edition)
278
+ } ;
277
279
let rest_pat = || {
278
- if token. kind ( ) != DOT2 {
280
+ if !is_same_kind || token. kind ( ) != DOT2 {
279
281
return None ;
280
282
}
281
283
@@ -289,7 +291,7 @@ fn hover_simple(
289
291
Some ( render:: struct_rest_pat ( sema, config, & record_pat, edition) )
290
292
} ;
291
293
let call = || {
292
- if token. kind ( ) != T ! [ '(' ] && token. kind ( ) != T ! [ ')' ] {
294
+ if !is_same_kind || token. kind ( ) != T ! [ '(' ] && token. kind ( ) != T ! [ ')' ] {
293
295
return None ;
294
296
}
295
297
let arg_list = token. parent ( ) . and_then ( ast:: ArgList :: cast) ?. syntax ( ) . parent ( ) ?;
@@ -303,7 +305,7 @@ fn hover_simple(
303
305
render:: type_info_of ( sema, config, & Either :: Left ( call_expr) , edition)
304
306
} ;
305
307
let closure = || {
306
- if token. kind ( ) != T ! [ |] {
308
+ if !is_same_kind || token. kind ( ) != T ! [ |] {
307
309
return None ;
308
310
}
309
311
let c = token. parent ( ) . and_then ( |x| x. parent ( ) ) . and_then ( ast:: ClosureExpr :: cast) ?;
0 commit comments