@@ -200,9 +200,16 @@ fn highlight_exit_points(
200
200
) -> Option < Vec < HighlightedRange > > {
201
201
fn hl (
202
202
sema : & Semantics < ' _ , RootDatabase > ,
203
+ def_ranges : [ Option < TextRange > ; 2 ] ,
203
204
body : Option < ast:: Expr > ,
204
205
) -> Option < Vec < HighlightedRange > > {
205
206
let mut highlights = Vec :: new ( ) ;
207
+ highlights. extend (
208
+ def_ranges
209
+ . into_iter ( )
210
+ . flatten ( )
211
+ . map ( |range| HighlightedRange { category : None , range } ) ,
212
+ ) ;
206
213
let body = body?;
207
214
walk_expr ( & body, & mut |expr| match expr {
208
215
ast:: Expr :: ReturnExpr ( expr) => {
@@ -246,10 +253,21 @@ fn highlight_exit_points(
246
253
for anc in token. parent_ancestors ( ) {
247
254
return match_ast ! {
248
255
match anc {
249
- ast:: Fn ( fn_) => hl( sema, fn_. body( ) . map( ast:: Expr :: BlockExpr ) ) ,
250
- ast:: ClosureExpr ( closure) => hl( sema, closure. body( ) ) ,
256
+ ast:: Fn ( fn_) => hl( sema, [ fn_. fn_token( ) . map( |it| it. text_range( ) ) , None ] , fn_. body( ) . map( ast:: Expr :: BlockExpr ) ) ,
257
+ ast:: ClosureExpr ( closure) => hl(
258
+ sema,
259
+ closure. param_list( ) . map_or( [ None ; 2 ] , |p| [ p. l_paren_token( ) . map( |it| it. text_range( ) ) , p. r_paren_token( ) . map( |it| it. text_range( ) ) ] ) ,
260
+ closure. body( )
261
+ ) ,
251
262
ast:: BlockExpr ( block_expr) => if matches!( block_expr. modifier( ) , Some ( ast:: BlockModifier :: Async ( _) | ast:: BlockModifier :: Try ( _) | ast:: BlockModifier :: Const ( _) ) ) {
252
- hl( sema, Some ( block_expr. into( ) ) )
263
+ hl(
264
+ sema,
265
+ [ block_expr. modifier( ) . and_then( |modifier| match modifier {
266
+ ast:: BlockModifier :: Async ( t) | ast:: BlockModifier :: Try ( t) | ast:: BlockModifier :: Const ( t) => Some ( t. text_range( ) ) ,
267
+ _ => None ,
268
+ } ) , None ] ,
269
+ Some ( block_expr. into( ) )
270
+ )
253
271
} else {
254
272
continue ;
255
273
} ,
@@ -663,7 +681,8 @@ async fn foo() {
663
681
fn test_hl_exit_points ( ) {
664
682
check (
665
683
r#"
666
- fn foo() -> u32 {
684
+ fn foo() -> u32 {
685
+ //^^
667
686
if true {
668
687
return$0 0;
669
688
// ^^^^^^
@@ -682,7 +701,8 @@ fn foo() -> u32 {
682
701
fn test_hl_exit_points2 ( ) {
683
702
check (
684
703
r#"
685
- fn foo() ->$0 u32 {
704
+ fn foo() ->$0 u32 {
705
+ //^^
686
706
if true {
687
707
return 0;
688
708
// ^^^^^^
@@ -701,7 +721,8 @@ fn foo() ->$0 u32 {
701
721
fn test_hl_exit_points3 ( ) {
702
722
check (
703
723
r#"
704
- fn$0 foo() -> u32 {
724
+ fn$0 foo() -> u32 {
725
+ //^^
705
726
if true {
706
727
return 0;
707
728
// ^^^^^^
@@ -747,7 +768,8 @@ macro_rules! never {
747
768
() => { never() }
748
769
}
749
770
fn never() -> ! { loop {} }
750
- fn foo() ->$0 u32 {
771
+ fn foo() ->$0 u32 {
772
+ //^^
751
773
never();
752
774
// ^^^^^^^
753
775
never!();
@@ -767,7 +789,8 @@ fn foo() ->$0 u32 {
767
789
fn test_hl_inner_tail_exit_points ( ) {
768
790
check (
769
791
r#"
770
- fn foo() ->$0 u32 {
792
+ fn foo() ->$0 u32 {
793
+ //^^
771
794
if true {
772
795
unsafe {
773
796
return 5;
@@ -808,7 +831,8 @@ fn foo() ->$0 u32 {
808
831
fn test_hl_inner_tail_exit_points_labeled_block ( ) {
809
832
check (
810
833
r#"
811
- fn foo() ->$0 u32 {
834
+ fn foo() ->$0 u32 {
835
+ //^^
812
836
'foo: {
813
837
break 'foo 0;
814
838
// ^^^^^
@@ -829,7 +853,8 @@ fn foo() ->$0 u32 {
829
853
fn test_hl_inner_tail_exit_points_loops ( ) {
830
854
check (
831
855
r#"
832
- fn foo() ->$0 u32 {
856
+ fn foo() ->$0 u32 {
857
+ //^^
833
858
'foo: while { return 0; true } {
834
859
// ^^^^^^
835
860
break 'foo 0;
@@ -1240,7 +1265,8 @@ fn foo() -> i32 {
1240
1265
1241
1266
check_with_config (
1242
1267
r#"
1243
- fn foo() ->$0 i32 {
1268
+ fn foo() ->$0 i32 {
1269
+ //^^
1244
1270
let x = 5;
1245
1271
let y = x * 2;
1246
1272
0 commit comments