diff options
| author | bors <bors@rust-lang.org> | 2024-07-20 05:11:10 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-07-20 05:11:10 +0000 |
| commit | 449517d52e884b4f42db065810bb732498fd75db (patch) | |
| tree | 47b02274aaeb35ce8862b60eed6f382bbc3468a9 | |
| parent | b939d3bf30a7a75585774b2597735144c0c264bf (diff) | |
| parent | 1669e930e19df3255ad40ff2e3e619e3f08051ab (diff) | |
| download | rust-449517d52e884b4f42db065810bb732498fd75db.tar.gz rust-449517d52e884b4f42db065810bb732498fd75db.zip | |
Auto merge of #17635 - Young-Flash:block_exp, r=lnicola
feat: add inlay hint support for block expr with lifetime label  close https://github.com/rust-lang/rust-analyzer/issues/17582
| -rw-r--r-- | src/tools/rust-analyzer/crates/ide/src/inlay_hints/closing_brace.rs | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/src/tools/rust-analyzer/crates/ide/src/inlay_hints/closing_brace.rs b/src/tools/rust-analyzer/crates/ide/src/inlay_hints/closing_brace.rs index d8aa4ba4e16..3e255adbe61 100644 --- a/src/tools/rust-analyzer/crates/ide/src/inlay_hints/closing_brace.rs +++ b/src/tools/rust-analyzer/crates/ide/src/inlay_hints/closing_brace.rs @@ -18,7 +18,7 @@ pub(super) fn hints( sema: &Semantics<'_, RootDatabase>, config: &InlayHintsConfig, file_id: EditionedFileId, - node: SyntaxNode, + mut node: SyntaxNode, ) -> Option<()> { let min_lines = config.closing_brace_hints_min_lines?; @@ -52,6 +52,14 @@ pub(super) fn hints( let module = ast::Module::cast(list.syntax().parent()?)?; (format!("mod {}", module.name()?), module.name().map(name)) + } else if let Some(label) = ast::Label::cast(node.clone()) { + // in this case, `ast::Label` could be seen as a part of `ast::BlockExpr` + // the actual number of lines in this case should be the line count of the parent BlockExpr, which the `min_lines` config care about + node = node.parent()?; + let block = label.syntax().parent().and_then(ast::BlockExpr::cast)?; + closing_token = block.stmt_list()?.r_curly_token()?; + let lifetime = label.lifetime().map_or_else(String::new, |it| it.to_string()); + (lifetime, Some(label.syntax().text_range())) } else if let Some(block) = ast::BlockExpr::cast(node.clone()) { closing_token = block.stmt_list()?.r_curly_token()?; @@ -192,4 +200,27 @@ fn f() { "#, ); } + + #[test] + fn hints_closing_brace_for_block_expr() { + check_with_config( + InlayHintsConfig { closing_brace_hints_min_lines: Some(2), ..DISABLED_CONFIG }, + r#" +fn test() { + 'end: { + 'do_a: { + 'do_b: { + + } + //^ 'do_b + break 'end; + } + //^ 'do_a + } + //^ 'end + } +//^ fn test +"#, + ); + } } |
