@@ -18,7 +18,7 @@ pub(super) fn hints(
18
18
sema : & Semantics < ' _ , RootDatabase > ,
19
19
config : & InlayHintsConfig ,
20
20
file_id : EditionedFileId ,
21
- node : SyntaxNode ,
21
+ mut node : SyntaxNode ,
22
22
) -> Option < ( ) > {
23
23
let min_lines = config. closing_brace_hints_min_lines ?;
24
24
@@ -52,6 +52,14 @@ pub(super) fn hints(
52
52
53
53
let module = ast:: Module :: cast ( list. syntax ( ) . parent ( ) ?) ?;
54
54
( format ! ( "mod {}" , module. name( ) ?) , module. name ( ) . map ( name) )
55
+ } else if let Some ( label) = ast:: Label :: cast ( node. clone ( ) ) {
56
+ // in this case, `ast::Label` could be seen as a part of `ast::BlockExpr`
57
+ // the actual number of lines in this case should be the line count of the parent BlockExpr, which the `min_lines` config care about
58
+ node = node. parent ( ) ?;
59
+ let block = label. syntax ( ) . parent ( ) . and_then ( ast:: BlockExpr :: cast) ?;
60
+ closing_token = block. stmt_list ( ) ?. r_curly_token ( ) ?;
61
+ let lifetime = label. lifetime ( ) . map_or_else ( String :: new, |it| it. to_string ( ) ) ;
62
+ ( lifetime, Some ( label. syntax ( ) . text_range ( ) ) )
55
63
} else if let Some ( block) = ast:: BlockExpr :: cast ( node. clone ( ) ) {
56
64
closing_token = block. stmt_list ( ) ?. r_curly_token ( ) ?;
57
65
@@ -189,6 +197,29 @@ fn f() {
189
197
];
190
198
}
191
199
//^ fn f
200
+ "# ,
201
+ ) ;
202
+ }
203
+
204
+ #[ test]
205
+ fn hints_closing_brace_for_block_expr ( ) {
206
+ check_with_config (
207
+ InlayHintsConfig { closing_brace_hints_min_lines : Some ( 2 ) , ..DISABLED_CONFIG } ,
208
+ r#"
209
+ fn test() {
210
+ 'end: {
211
+ 'do_a: {
212
+ 'do_b: {
213
+
214
+ }
215
+ //^ 'do_b
216
+ break 'end;
217
+ }
218
+ //^ 'do_a
219
+ }
220
+ //^ 'end
221
+ }
222
+ //^ fn test
192
223
"# ,
193
224
) ;
194
225
}
0 commit comments