Skip to content

Commit 1a1deeb

Browse files
committed
feat: add inlay hint support for block expr with lifetime label
1 parent a62ea0a commit 1a1deeb

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

crates/ide/src/inlay_hints/closing_brace.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub(super) fn hints(
1717
sema: &Semantics<'_, RootDatabase>,
1818
config: &InlayHintsConfig,
1919
file_id: FileId,
20-
node: SyntaxNode,
20+
mut node: SyntaxNode,
2121
) -> Option<()> {
2222
let min_lines = config.closing_brace_hints_min_lines?;
2323

@@ -51,6 +51,13 @@ pub(super) fn hints(
5151

5252
let module = ast::Module::cast(list.syntax().parent()?)?;
5353
(format!("mod {}", module.name()?), module.name().map(name))
54+
} else if let Some(label) = ast::Label::cast(node.clone()) {
55+
// in this case, `ast::Label` could be seen as a part of `ast::BlockExpr`, to respect the `min_lines` config
56+
node = node.parent()?;
57+
let block = label.syntax().parent().and_then(ast::BlockExpr::cast)?;
58+
closing_token = block.stmt_list()?.r_curly_token()?;
59+
let lifetime = label.lifetime().map_or_else(String::new, |it| it.to_string());
60+
(lifetime, Some(label.syntax().text_range()))
5461
} else if let Some(block) = ast::BlockExpr::cast(node.clone()) {
5562
closing_token = block.stmt_list()?.r_curly_token()?;
5663

0 commit comments

Comments
 (0)