-
Notifications
You must be signed in to change notification settings - Fork 1.8k
SSR: Support statement matching and replacing #6587
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -212,6 +212,13 @@ impl ast::Attr { | |
} | ||
} | ||
|
||
impl ast::Stmt { | ||
/// Returns `text`, parsed as statement, but only if it has no errors. | ||
pub fn parse(text: &str) -> Result<Self, ()> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It'd be nice to add a test for this function. The other parse functions in this file have tests - see test.rs in this directory There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair point. Doesn't seem like every type ( Not sure what to add for the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I hadn't seen the parser for For error cases, I guess:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just letting you know in case you feel like adding more tests to the other parsers. Apart your suggestions I've added a bunch of items, expressions and blocks to the mix that can be parsed as |
||
parsing::parse_text_fragment(text, parser::FragmentKind::StatementOptionalSemi) | ||
} | ||
} | ||
|
||
/// Matches a `SyntaxNode` against an `ast` type. | ||
/// | ||
/// # Example: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ERROR |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#[foo] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ERROR |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
a(); b(); c() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ERROR |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
( |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ERROR |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ERROR |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1 + |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[email protected] | ||
[email protected] | ||
[email protected] | ||
[email protected] "1" | ||
[email protected] " " | ||
[email protected] "+" | ||
[email protected] " " | ||
[email protected] | ||
[email protected] "1" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1 + 1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
let x = foo(); | ||
let y = bar(); | ||
Ok(x + y) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[email protected] | ||
[email protected] | ||
[email protected] | ||
[email protected] | ||
[email protected] | ||
[email protected] | ||
[email protected] "foo" | ||
[email protected] | ||
[email protected] "(" | ||
[email protected] ")" | ||
[email protected] ";" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
foo(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[email protected] | ||
[email protected] "let" | ||
[email protected] " " | ||
[email protected] | ||
[email protected] | ||
[email protected] "x" | ||
[email protected] " " | ||
[email protected] "=" | ||
[email protected] " " | ||
[email protected] | ||
[email protected] "10" | ||
[email protected] ";" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
let x = 10; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
[email protected] | ||
[email protected] | ||
[email protected] | ||
[email protected] | ||
[email protected] | ||
[email protected] "m1" | ||
[email protected] "!" | ||
[email protected] | ||
[email protected] "{" | ||
[email protected] " " | ||
[email protected] "let" | ||
[email protected] " " | ||
[email protected] "a" | ||
[email protected] " " | ||
[email protected] "=" | ||
[email protected] " " | ||
[email protected] "0" | ||
[email protected] ";" | ||
[email protected] " " | ||
[email protected] "}" | ||
[email protected] ";" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
m1!{ let a = 0; }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
[email protected] | ||
[email protected] | ||
[email protected] | ||
[email protected] | ||
[email protected] | ||
[email protected] "m1" | ||
[email protected] "!" | ||
[email protected] | ||
[email protected] "{" | ||
[email protected] " " | ||
[email protected] "let" | ||
[email protected] " " | ||
[email protected] "a" | ||
[email protected] " " | ||
[email protected] "=" | ||
[email protected] " " | ||
[email protected] "0" | ||
[email protected] ";" | ||
[email protected] " " | ||
[email protected] "}" | ||
[email protected] ";" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
m1!{ let a = 0; }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
[email protected] | ||
[email protected] "struct" | ||
[email protected] " " | ||
[email protected] | ||
[email protected] "Foo" | ||
[email protected] " " | ||
[email protected] | ||
[email protected] "{" | ||
[email protected] "\n " | ||
[email protected] | ||
[email protected] | ||
[email protected] "bar" | ||
[email protected] ":" | ||
[email protected] " " | ||
[email protected] | ||
[email protected] | ||
[email protected] | ||
[email protected] | ||
[email protected] "u32" | ||
[email protected] "," | ||
[email protected] "\n" | ||
[email protected] "}" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
struct Foo { | ||
bar: u32, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[email protected] | ||
[email protected] | ||
[email protected] | ||
[email protected] | ||
[email protected] | ||
[email protected] | ||
[email protected] "foo" | ||
[email protected] | ||
[email protected] "(" | ||
[email protected] ")" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
foo() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[email protected] | ||
[email protected] "let" | ||
[email protected] " " | ||
[email protected] | ||
[email protected] | ||
[email protected] "x" | ||
[email protected] " " | ||
[email protected] "=" | ||
[email protected] " " | ||
[email protected] | ||
[email protected] "10" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
let x = 10 |
Uh oh!
There was an error while loading. Please reload this page.