diff options
| author | Young-Flash <dongyang@apache.org> | 2024-07-16 22:16:25 +0800 |
|---|---|---|
| committer | Young-Flash <dongyang@apache.org> | 2024-07-20 09:33:23 +0800 |
| commit | aee0e30bedce88b8adadfbdbb4c93ce2c0cf492a (patch) | |
| tree | 214524428e486b16d1a1621acbb0d00572cd1366 | |
| parent | b939d3bf30a7a75585774b2597735144c0c264bf (diff) | |
| download | rust-aee0e30bedce88b8adadfbdbb4c93ce2c0cf492a.tar.gz rust-aee0e30bedce88b8adadfbdbb4c93ce2c0cf492a.zip | |
feat: add inlay hint support for block expr with lifetime label
| -rw-r--r-- | src/tools/rust-analyzer/crates/ide/src/inlay_hints/closing_brace.rs | 9 |
1 files changed, 8 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..de11ca4f690 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,13 @@ 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`, to respect the `min_lines` config + 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()?; |
