Unnamed repository; edit this file 'description' to name the repository.
fix doc test.
l1nxy 2024-01-01
parent edb9ad2 · commit b6a14ce
-rw-r--r--crates/ide-assists/src/handlers/merge_nested_if.rs32
-rw-r--r--crates/ide-assists/src/tests/generated.rs14
2 files changed, 24 insertions, 22 deletions
diff --git a/crates/ide-assists/src/handlers/merge_nested_if.rs b/crates/ide-assists/src/handlers/merge_nested_if.rs
index 39db42faae..206bc3e08b 100644
--- a/crates/ide-assists/src/handlers/merge_nested_if.rs
+++ b/crates/ide-assists/src/handlers/merge_nested_if.rs
@@ -8,22 +8,22 @@ use crate::{
assist_context::{AssistContext, Assists},
AssistId, AssistKind,
};
-/// Assist: merge_nested_if
-///
-/// This transforms if expressions of the form `if x { if y {A} }` into `if x && y {A}`
-/// This assist can only be applied with the cursor on `if`.
-///
-/// ```
-/// fn main() {
-/// i$0f x == 3 { if y == 4 { 1 } }
-/// }
-/// ```
-/// ->
-/// ```
-/// fn main() {
-/// if x == 3 && y == 4 { 1 }
-/// }
-/// ```
+// Assist: merge_nested_if
+//
+// This transforms if expressions of the form `if x { if y {A} }` into `if x && y {A}`
+// This assist can only be applied with the cursor on `if`.
+//
+// ```
+// fn main() {
+// i$0f x == 3 { if y == 4 { 1 } }
+// }
+// ```
+// ->
+// ```
+// fn main() {
+// if x == 3 && y == 4 { 1 }
+// }
+// ```
pub(crate) fn merge_nested_if(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
let if_keyword = ctx.find_token_syntax_at_offset(T![if])?;
let expr = ast::IfExpr::cast(if_keyword.parent()?)?;
diff --git a/crates/ide-assists/src/tests/generated.rs b/crates/ide-assists/src/tests/generated.rs
index 79958a2292..d8b3b32a1a 100644
--- a/crates/ide-assists/src/tests/generated.rs
+++ b/crates/ide-assists/src/tests/generated.rs
@@ -2056,13 +2056,15 @@ fn doctest_merge_nested_if() {
check_doc_test(
"merge_nested_if",
r#####"
- fn main() {
- i$0f x == 3 { if y == 4 { 1 } }
- }"#####,
+fn main() {
+ i$0f x == 3 { if y == 4 { 1 } }
+}
+"#####,
r#####"
- fn main() {
- if x == 3 && y == 4 { 1 }
- }"#####,
+fn main() {
+ if x == 3 && y == 4 { 1 }
+}
+"#####,
)
}