aboutsummaryrefslogtreecommitdiff
path: root/crates/ssr
Commit message (Collapse)AuthorAgeFilesLines
* Merge #7147bors[bot]2021-01-042-3/+60
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 7147: ssr: Allow replacing expressions with statements r=davidlattimore a=MarijnS95 Depends on #6587 Until that is merged, the diff is https://github.com/MarijnS95/rust-analyzer/compare/stmt..replace-expr-with-stmt --- Now that statements can be matched and replaced (#6587) some usecases require expressions to be replaced with statements as well. This happens when something that can ambiguously be an expression or statement like `if` and loop blocks appear in the last position of a block, as trailing expression. In this case a replacement pattern of the form `if foo(){$a();}==>>$a();` will only substitute `if` blocks in the list of statements but not if they (implicitly) end up in the trailing expression, where they are not wrapped by an EXPR_STMT (but the pattern and template are, as parsing only succeeds for the `stmt ==>> stmt` case). Instead of adding two rules that match an expression - and emit duplicate matching errors - allow the template for expressions to be a statement if it fails to parse as an expression. --- Another gross change that does not seem to break any tests currently, but perhaps a safeguard should be added to only allow this kind of replacement in blocks by "pushing" the replacement template to the statement list and clearing the trailing expression? CC @davidlattimore Co-authored-by: Marijn Suijten <[email protected]>
| * ssr: Allow replacing expressions with statementsMarijn Suijten2021-01-042-3/+60
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Now that statements can be matched and replaced (#6587) some usecases require expressions to be replaced with statements as well. This happens when something that can ambiguously be an expression or statement like `if` and loop blocks appear in the last position of a block, as trailing expression. In this case a replacement pattern of the form `if foo(){$a();}==>>$a();` will only substitute `if` blocks in the list of statements but not if they (implicitly) end up in the trailing expression, where they are not wrapped by an EXPR_STMT (but the pattern and template are, as parsing only succeeds for the `stmt ==>> stmt` case). Instead of adding two rules that match an expression - and emit duplicate matching errors - allow the template for expressions to be a statement if it fails to parse as an expression.
* | Merge #6587bors[bot]2021-01-042-0/+45
|\| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 6587: SSR: Support statement matching and replacing r=davidlattimore a=MarijnS95 For #3186 Hi! This is a smaller initial patchset that came up while working on support for statement lists (and my first time working on RA :grin:). It has me stuck on trailing semicolons for which I hope to receive some feedback. Matching (and replacing) `let` bindings with a trailing semicolon works fine, but trying to omit these (to make patterns more ergonomic) turns out more complex than expected. The "optional trailing semicolon solution" implemented in this PR is ugly because `Matcher::attempt_match_token` should only consume a trailing `;` when parsing `let` bindings to prevent other code from breaking. That at the same time has a nasty side-effect of `;` ending up in the matched code: any replacements on that should include the trailing semicolon as well even if it was not in the pattern. A better example is in the tests: https://github.com/rust-analyzer/rust-analyzer/blob/3ae1649c24a689473b874c331f5f176e5839978e/crates/ssr/src/tests.rs#L178-L184 The end result to achieve is (I guess) allowing replacement of let bindings without trailing semicolon like `let x = $a ==>> let x = 1` (but including them on both sides is still fine), and should make replacement in a macro call (where `foo!(let a = 2;)` for a `$x:stmt` is invalid syntax) possible as well. That should allow to enable/fix these tests: https://github.com/rust-analyzer/rust-analyzer/blob/3ae1649c24a689473b874c331f5f176e5839978e/crates/ssr/src/tests.rs#L201-L214 A possible MVP of this PR might be to drop this optional `;' handling entirely and only allow an SSR pattern/template with semicolons on either side. Co-authored-by: Marijn Suijten <[email protected]>
| * ssr: Add tests for raw LetStmt matchingMarijn Suijten2021-01-031-0/+44
| |
| * syntax,ssr: Implement statement parsingMarijn Suijten2021-01-031-0/+1
| |
* | Upgrade expect-test to 1.1Jesse Bakker2021-01-031-1/+1
|/
* Remove some unneeded string allocationsLukas Wirth2020-12-311-1/+3
|
* Update crateskjeremy2020-12-301-1/+1
|
* Remove more unreachable pubsAleksey Kladov2020-11-021-1/+1
|
* Re-export base_db from ide_dbIgor Aleksanov2020-10-246-12/+11
|
* Minor clippy performance suggestionskjeremy2020-09-301-1/+1
|
* :arrow_up: expect-testAleksey Kladov2020-08-281-1/+1
|
* Add version to deps in cargo.tomlPavan Kumar Sunkara2020-08-241-6/+6
|
* :arrow_up: ungrammarAleksey Kladov2020-08-212-8/+7
|
* Switch to expect_test from crates.ioAleksey Kladov2020-08-212-2/+2
|
* Future proof find-usages APIAleksey Kladov2020-08-191-1/+1
| | | | | | We might want to provide more efficient impls for check if usages exist, limiting the search, filtering and cancellation, so let's violate YAGNI a bit here.
* Add SelfParam to code_modelAleksey Kladov2020-08-192-2/+2
|
* Merge #5758bors[bot]2020-08-186-38/+246
|\ | | | | | | | | | | | | | | | | | | 5758: SSR: Explicitly autoderef and ref placeholders as needed r=matklad a=davidlattimore Structural search replace now inserts *, & and &mut in the replacement to match any auto[de]ref in the matched code. e.g. `$a.foo() ==>> bar($a)` might convert `x.foo()` to `bar(&mut x)` Co-authored-by: David Lattimore <[email protected]>
| * SSR: A few small refactoringsDavid Lattimore2020-08-183-6/+9
| |
| * SSR: Explicitly autoderef and ref placeholders as neededDavid Lattimore2020-08-144-25/+222
| | | | | | | | Structured search replace now inserts *, & and &mut in the replacement to match any auto[de]ref in the matched code.
| * Refactor SSR so that placeholders store a VarDavid Lattimore2020-08-144-18/+26
| | | | | | | | | | This allows lookup of placeholder bindings given a placeholder without needing to create a Var instance.
* | Rename hypothetical -> speculativeAleksey Kladov2020-08-141-2/+2
|/
* Make hygiene private to hirAleksey Kladov2020-08-131-11/+13
|
* Rename ra_ide -> ideAleksey Kladov2020-08-131-1/+1
|
* Rename ra_ssr -> ssrAleksey Kladov2020-08-1310-0/+3600