about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJeroen Vannevel <jer_vannevel@outlook.com>2022-01-22 11:42:03 +0000
committerJeroen Vannevel <jer_vannevel@outlook.com>2022-01-22 12:08:32 +0000
commit96ab4c6e6cad30b8ae2fd3db07cb5eea764db011 (patch)
tree376bea5bd49aff1e63615032fc2fd34675048f55
parent5d35e5882c26d7cb3cebbb6670a15d9118e8153c (diff)
downloadrust-96ab4c6e6cad30b8ae2fd3db07cb5eea764db011.tar.gz
rust-96ab4c6e6cad30b8ae2fd3db07cb5eea764db011.zip
hacky_block_expr_with_comments
-rw-r--r--crates/ide_assists/src/handlers/extract_function.rs4
-rw-r--r--crates/syntax/src/ast/make.rs17
2 files changed, 10 insertions, 11 deletions
diff --git a/crates/ide_assists/src/handlers/extract_function.rs b/crates/ide_assists/src/handlers/extract_function.rs
index 06195624ed0..3160bd5293a 100644
--- a/crates/ide_assists/src/handlers/extract_function.rs
+++ b/crates/ide_assists/src/handlers/extract_function.rs
@@ -1524,9 +1524,7 @@ fn make_body(
                 println!("element: {:?}", element);
             }
 
-            make::block_expr_full(elements, tail_expr)
-
-            // make::block_expr(parent.statements().into_iter(), tail_expr)
+            make::hacky_block_expr_with_comments(elements, tail_expr)
         }
     };
 
diff --git a/crates/syntax/src/ast/make.rs b/crates/syntax/src/ast/make.rs
index 2d1e9ac05d2..9498defb3f3 100644
--- a/crates/syntax/src/ast/make.rs
+++ b/crates/syntax/src/ast/make.rs
@@ -329,17 +329,18 @@ pub fn block_expr(
     ast_from_text(&format!("fn f() {}", buf))
 }
 
-pub fn block_expr_full(
-    stmts: impl IntoIterator<Item = crate::SyntaxElement>,
+/// Ideally this function wouldn't exist since it involves manual indenting.
+/// It differs from `make::block_expr` by also supporting comments.
+/// 
+/// FIXME: replace usages of this with the mutable syntax tree API
+pub fn hacky_block_expr_with_comments(
+    elements: impl IntoIterator<Item = crate::SyntaxElement>,
     tail_expr: Option<ast::Expr>,
 ) -> ast::BlockExpr {
     let mut buf = "{\n".to_string();
-    for stmt in stmts.into_iter() {
-        match stmt {
-            rowan::NodeOrToken::Node(n) => {
-                println!("Node: {:?}", n.text());
-                format_to!(buf, "    {}\n", n)
-            }
+    for node_or_token in elements.into_iter() {
+        match node_or_token {
+            rowan::NodeOrToken::Node(n) => format_to!(buf, "    {}\n", n),
             rowan::NodeOrToken::Token(t) if t.kind() == SyntaxKind::COMMENT => {
                 format_to!(buf, "    {}\n", t)
             }