Skip to content

Commit 722020e

Browse files
committed
feat: support inlay hint for more expr with label
1 parent 9fcaab3 commit 722020e

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

crates/ide/src/inlay_hints/closing_brace.rs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use hir::{HirDisplay, Semantics};
77
use ide_db::{FileRange, RootDatabase};
88
use span::EditionedFileId;
99
use syntax::{
10-
ast::{self, AstNode, HasName},
10+
ast::{self, AstNode, HasLoopBody, HasName},
1111
match_ast, SyntaxKind, SyntaxNode, T,
1212
};
1313

@@ -57,9 +57,30 @@ pub(super) fn hints(
5757
// the actual number of lines in this case should be the line count of the parent BlockExpr,
5858
// which the `min_lines` config cares about
5959
node = node.parent()?;
60-
let block = label.syntax().parent().and_then(ast::BlockExpr::cast)?;
61-
closing_token = block.stmt_list()?.r_curly_token()?;
60+
61+
let parent = label.syntax().parent()?;
62+
let block;
63+
match_ast! {
64+
match parent {
65+
ast::BlockExpr(block_expr) => {
66+
block = block_expr.stmt_list()?;
67+
},
68+
ast::LoopExpr(loop_expr) => {
69+
block = loop_expr.loop_body()?.stmt_list()?;
70+
},
71+
ast::WhileExpr(while_expr) => {
72+
block = while_expr.loop_body()?.stmt_list()?;
73+
},
74+
ast::ForExpr(for_expr) => {
75+
block = for_expr.loop_body()?.stmt_list()?;
76+
},
77+
_ => return None,
78+
}
79+
}
80+
closing_token = block.r_curly_token()?;
81+
6282
let lifetime = label.lifetime().map_or_else(String::new, |it| it.to_string());
83+
6384
(lifetime, Some(label.syntax().text_range()))
6485
} else if let Some(block) = ast::BlockExpr::cast(node.clone()) {
6586
closing_token = block.stmt_list()?.r_curly_token()?;

0 commit comments

Comments
 (0)