about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-08-05 12:03:18 +0000
committerbors <bors@rust-lang.org>2024-08-05 12:03:18 +0000
commit78dea2465c5b8b4e63ac8c7f4a0e39345fa82410 (patch)
treec1fa2e95416f4b86a445bb0e4586339e89fd46c9
parent68253247638c1a28b90ab0a172a2d9bb47d6e909 (diff)
parentf12aca95e4badcb079c2615b55f1c85e845b22e7 (diff)
downloadrust-78dea2465c5b8b4e63ac8c7f4a0e39345fa82410.tar.gz
rust-78dea2465c5b8b4e63ac8c7f4a0e39345fa82410.zip
Auto merge of #17784 - Young-Flash:block_with_label, r=Veykril
feat: support inlay hint for more expr with label

follow up https://github.com/rust-lang/rust-analyzer/pull/17635
-rw-r--r--src/tools/rust-analyzer/crates/ide/src/inlay_hints/closing_brace.rs34
1 files changed, 31 insertions, 3 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 ea96c9504e5..8f2777f3928 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
@@ -7,7 +7,7 @@ use hir::{HirDisplay, Semantics};
 use ide_db::{FileRange, RootDatabase};
 use span::EditionedFileId;
 use syntax::{
-    ast::{self, AstNode, HasName},
+    ast::{self, AstNode, HasLoopBody, HasName},
     match_ast, SyntaxKind, SyntaxNode, T,
 };
 
@@ -57,9 +57,24 @@ pub(super) fn hints(
         // the actual number of lines in this case should be the line count of the parent BlockExpr,
         // which the `min_lines` config cares about
         node = node.parent()?;
-        let block = label.syntax().parent().and_then(ast::BlockExpr::cast)?;
-        closing_token = block.stmt_list()?.r_curly_token()?;
+
+        let parent = label.syntax().parent()?;
+        let block;
+        match_ast! {
+            match parent {
+                ast::BlockExpr(block_expr) => {
+                    block = block_expr.stmt_list()?;
+                },
+                ast::AnyHasLoopBody(loop_expr) => {
+                    block = loop_expr.loop_body()?.stmt_list()?;
+                },
+                _ => return None,
+            }
+        }
+        closing_token = block.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()?;
@@ -219,6 +234,19 @@ fn test() {
       //^ 'do_a
     }
   //^ 'end
+
+    'a: loop {
+        'b: for i in 0..5 {
+            'c: while true {
+
+
+            }
+          //^ 'c
+        }
+      //^ 'b
+    }
+  //^ 'a
+
   }
 //^ fn test
 "#,