@@ -119,7 +119,7 @@ pub(crate) fn hover(
119119 let edition =
120120 sema. attach_first_edition ( file_id) . map ( |it| it. edition ( ) ) . unwrap_or ( Edition :: CURRENT ) ;
121121 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)
123123 } else {
124124 hover_ranged ( sema, frange, file, config, edition)
125125 } ?;
@@ -131,7 +131,7 @@ pub(crate) fn hover(
131131}
132132
133133#[ allow( clippy:: field_reassign_with_default) ]
134- fn hover_simple (
134+ fn hover_offset (
135135 sema : & Semantics < ' _ , RootDatabase > ,
136136 FilePosition { file_id, offset } : FilePosition ,
137137 file : SyntaxNode ,
@@ -186,26 +186,23 @@ fn hover_simple(
186186 let text = original_token. text ( ) ;
187187 let ident_kind = kind. is_any_identifier ( ) ;
188188
189- descended. sort_by_key ( |tok| {
189+ descended. sort_by_cached_key ( |tok| {
190190 let tok_kind = tok. kind ( ) ;
191191
192192 let exact_same_kind = tok_kind == kind;
193193 let both_idents = exact_same_kind || ( tok_kind. is_any_identifier ( ) && ident_kind) ;
194194 let same_text = tok. text ( ) == text;
195195 // anything that mapped into a token tree has likely no semantic information
196196 let no_tt_parent = tok. parent ( ) . map_or ( false , |it| it. kind ( ) != TOKEN_TREE ) ;
197- ( both_idents as usize )
197+ ! ( ( both_idents as usize )
198198 | ( ( exact_same_kind as usize ) << 1 )
199199 | ( ( same_text as usize ) << 2 )
200- | ( ( no_tt_parent as usize ) << 3 )
200+ | ( ( no_tt_parent as usize ) << 3 ) )
201201 } ) ;
202202
203203 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- // };
208204 for token in descended {
205+ let is_same_kind = token. kind ( ) == kind;
209206 let lint_hover = ( || {
210207 // FIXME: Definition should include known lints and the like instead of having this special case here
211208 let attr = token. parent_ancestors ( ) . find_map ( ast:: Attr :: cast) ?;
@@ -273,9 +270,14 @@ fn hover_simple(
273270 continue ;
274271 }
275272 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+ } ;
277279 let rest_pat = || {
278- if token. kind ( ) != DOT2 {
280+ if !is_same_kind || token. kind ( ) != DOT2 {
279281 return None ;
280282 }
281283
@@ -289,7 +291,7 @@ fn hover_simple(
289291 Some ( render:: struct_rest_pat ( sema, config, & record_pat, edition) )
290292 } ;
291293 let call = || {
292- if token. kind ( ) != T ! [ '(' ] && token. kind ( ) != T ! [ ')' ] {
294+ if !is_same_kind || token. kind ( ) != T ! [ '(' ] && token. kind ( ) != T ! [ ')' ] {
293295 return None ;
294296 }
295297 let arg_list = token. parent ( ) . and_then ( ast:: ArgList :: cast) ?. syntax ( ) . parent ( ) ?;
@@ -303,7 +305,7 @@ fn hover_simple(
303305 render:: type_info_of ( sema, config, & Either :: Left ( call_expr) , edition)
304306 } ;
305307 let closure = || {
306- if token. kind ( ) != T ! [ |] {
308+ if !is_same_kind || token. kind ( ) != T ! [ |] {
307309 return None ;
308310 }
309311 let c = token. parent ( ) . and_then ( |x| x. parent ( ) ) . and_then ( ast:: ClosureExpr :: cast) ?;
0 commit comments