mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 05:45:12 +00:00
Add some more syntax fixup rules
This commit is contained in:
parent
f11891f882
commit
158626bed4
1 changed files with 122 additions and 1 deletions
|
@ -91,7 +91,6 @@ pub(crate) fn fixup_syntax(
|
||||||
preorder.skip_subtree();
|
preorder.skip_subtree();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// In some other situations, we can fix things by just appending some tokens.
|
// In some other situations, we can fix things by just appending some tokens.
|
||||||
match_ast! {
|
match_ast! {
|
||||||
match node {
|
match node {
|
||||||
|
@ -276,6 +275,62 @@ pub(crate) fn fixup_syntax(
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
ast::RecordExprField(it) => {
|
||||||
|
if let Some(colon) = it.colon_token() {
|
||||||
|
if it.name_ref().is_some() {
|
||||||
|
append.insert(colon.into(), vec![
|
||||||
|
Leaf::Ident(Ident {
|
||||||
|
text: "__ra_fixup".into(),
|
||||||
|
span: fake_span(node_range)
|
||||||
|
})
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
ast::Path(it) => {
|
||||||
|
if let Some(colon) = it.coloncolon_token() {
|
||||||
|
if it.segment().is_none() {
|
||||||
|
append.insert(colon.into(), vec![
|
||||||
|
Leaf::Ident(Ident {
|
||||||
|
text: "__ra_fixup".into(),
|
||||||
|
span: fake_span(node_range)
|
||||||
|
})
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
ast::ArgList(it) => {
|
||||||
|
if it.r_paren_token().is_none() {
|
||||||
|
append.insert(node.into(), vec![
|
||||||
|
Leaf::Punct(Punct {
|
||||||
|
span: fake_span(node_range),
|
||||||
|
char: ')',
|
||||||
|
spacing: Spacing::Alone
|
||||||
|
})
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
ast::ArgList(it) => {
|
||||||
|
if it.r_paren_token().is_none() {
|
||||||
|
append.insert(node.into(), vec![
|
||||||
|
Leaf::Punct(Punct {
|
||||||
|
span: fake_span(node_range),
|
||||||
|
char: ')',
|
||||||
|
spacing: Spacing::Alone
|
||||||
|
})
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
ast::ClosureExpr(it) => {
|
||||||
|
if it.body().is_none() {
|
||||||
|
append.insert(node.into(), vec![
|
||||||
|
Leaf::Ident(Ident {
|
||||||
|
text: "__ra_fixup".into(),
|
||||||
|
span: fake_span(node_range)
|
||||||
|
})
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
},
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -759,4 +814,70 @@ fn foo () {loop { }}
|
||||||
"#]],
|
"#]],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn fixup_path() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
fn foo() {
|
||||||
|
path::
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
fn foo () {path :: __ra_fixup}
|
||||||
|
"#]],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn fixup_record_ctor_field() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
fn foo() {
|
||||||
|
R { f: }
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
fn foo () {R {f : __ra_fixup}}
|
||||||
|
"#]],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn fixup_arg_list() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
fn foo() {
|
||||||
|
foo(a
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
fn foo () { foo ( a ) }
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
fn foo() {
|
||||||
|
bar.foo(a
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
fn foo () { bar . foo ( a ) }
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn fixup_closure() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
fn foo() {
|
||||||
|
||
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
fn foo () {|| __ra_fixup}
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue