@@ -31,8 +31,10 @@ pub struct HighlightRelatedConfig {
31
31
// Highlights constructs related to the thing under the cursor:
32
32
// - if on an identifier, highlights all references to that identifier in the current file
33
33
// - if on an `async` or `await token, highlights all yield points for that async context
34
- // - if on a `return` token , `?` character or `->` return type arrow, highlights all exit points for that context
34
+ // - if on a `return` or `fn` keyword , `?` character or `->` return type arrow, highlights all exit points for that context
35
35
// - if on a `break`, `loop`, `while` or `for` token, highlights all break points for that loop or block context
36
+ //
37
+ // Note: `?` and `->` do not currently trigger this behavior in the VSCode editor.
36
38
pub ( crate ) fn highlight_related (
37
39
sema : & Semantics < RootDatabase > ,
38
40
config : HighlightRelatedConfig ,
@@ -42,20 +44,16 @@ pub(crate) fn highlight_related(
42
44
let syntax = sema. parse ( position. file_id ) . syntax ( ) . clone ( ) ;
43
45
44
46
let token = pick_best_token ( syntax. token_at_offset ( position. offset ) , |kind| match kind {
45
- T ! [ ?] => 2 , // prefer `?` when the cursor is sandwiched like `await$0?`
46
- T ! [ await ]
47
- | T ! [ async ]
48
- | T ! [ return ]
49
- | T ! [ break ]
50
- | T ! [ loop ]
51
- | T ! [ for ]
52
- | T ! [ while ]
53
- | T ! [ ->] => 1 ,
47
+ T ! [ ?] => 3 , // prefer `?` when the cursor is sandwiched like in `await$0?`
48
+ T ! [ ->] => 2 ,
49
+ kind if kind. is_keyword ( ) => 1 ,
54
50
_ => 0 ,
55
51
} ) ?;
56
52
57
53
match token. kind ( ) {
58
- T ! [ return ] | T ! [ ?] | T ! [ ->] if config. exit_points => highlight_exit_points ( sema, token) ,
54
+ T ! [ fn ] | T ! [ return ] | T ! [ ?] | T ! [ ->] if config. exit_points => {
55
+ highlight_exit_points ( sema, token)
56
+ }
59
57
T ! [ await ] | T ! [ async ] if config. yield_points => highlight_yield_points ( token) ,
60
58
T ! [ break ] | T ! [ loop ] | T ! [ for ] | T ! [ while ] if config. break_points => {
61
59
highlight_break_points ( token)
@@ -474,6 +472,25 @@ fn foo() ->$0 u32 {
474
472
) ;
475
473
}
476
474
475
+ #[ test]
476
+ fn test_hl_exit_points3 ( ) {
477
+ check (
478
+ r#"
479
+ fn$0 foo() -> u32 {
480
+ if true {
481
+ return 0;
482
+ // ^^^^^^
483
+ }
484
+
485
+ 0?;
486
+ // ^
487
+ 0xDEAD_BEEF
488
+ // ^^^^^^^^^^^
489
+ }
490
+ "# ,
491
+ ) ;
492
+ }
493
+
477
494
#[ test]
478
495
fn test_hl_prefer_ref_over_tail_exit ( ) {
479
496
check (
0 commit comments