Skip to content

Commit 6546932

Browse files
committed
Add syntax fixup for while loops
1 parent 1c75284 commit 6546932

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

crates/hir-expand/src/fixup.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,37 @@ pub(crate) fn fixup_syntax(node: &SyntaxNode) -> SyntaxFixups {
142142
]);
143143
}
144144
},
145+
ast::WhileExpr(it) => {
146+
if it.condition().is_none() {
147+
// insert placeholder token after the while token
148+
let while_token = match it.while_token() {
149+
Some(t) => t,
150+
None => continue,
151+
};
152+
append.insert(while_token.into(), vec![
153+
SyntheticToken {
154+
kind: SyntaxKind::IDENT,
155+
text: "__ra_fixup".into(),
156+
range: end_range,
157+
id: EMPTY_ID,
158+
},
159+
]);
160+
append.insert(node.clone().into(), vec![
161+
SyntheticToken {
162+
kind: SyntaxKind::L_CURLY,
163+
text: "{".into(),
164+
range: end_range,
165+
id: EMPTY_ID,
166+
},
167+
SyntheticToken {
168+
kind: SyntaxKind::R_CURLY,
169+
text: "}".into(),
170+
range: end_range,
171+
id: EMPTY_ID,
172+
},
173+
]);
174+
}
175+
},
145176
// FIXME: foo::
146177
// FIXME: for, loop, match etc.
147178
_ => (),
@@ -376,6 +407,20 @@ fn foo() {
376407
// the {} gets parsed as the condition, I think?
377408
expect![[r#"
378409
fn foo () {if {} {}}
410+
"#]],
411+
)
412+
}
413+
414+
#[test]
415+
fn fixup_while_1() {
416+
check(
417+
r#"
418+
fn foo() {
419+
while
420+
}
421+
"#,
422+
expect![[r#"
423+
fn foo () {while __ra_fixup {}}
379424
"#]],
380425
)
381426
}

0 commit comments

Comments
 (0)