@@ -18,7 +18,7 @@ pub(super) fn hints(
1818 sema : & Semantics < ' _ , RootDatabase > ,
1919 config : & InlayHintsConfig ,
2020 file_id : EditionedFileId ,
21- node : SyntaxNode ,
21+ mut node : SyntaxNode ,
2222) -> Option < ( ) > {
2323 let min_lines = config. closing_brace_hints_min_lines ?;
2424
@@ -52,6 +52,14 @@ pub(super) fn hints(
5252
5353 let module = ast:: Module :: cast ( list. syntax ( ) . parent ( ) ?) ?;
5454 ( 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 ( ) ) )
5563 } else if let Some ( block) = ast:: BlockExpr :: cast ( node. clone ( ) ) {
5664 closing_token = block. stmt_list ( ) ?. r_curly_token ( ) ?;
5765
@@ -189,6 +197,29 @@ fn f() {
189197 ];
190198 }
191199//^ 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
192223"# ,
193224 ) ;
194225 }
0 commit comments