aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ssr/src/lib.rs
Commit message (Collapse)AuthorAgeFilesLines
* SSR: Allow `self` in patterns.David Lattimore2020-08-011-6/+1
| | | | | | | | | It's now consistent with other variables in that if the pattern references self, only the `self` in scope where the rule is invoked will be accepted. Since `self` doesn't work the same as other paths, this is implemented by restricting the search to just the current function. Prior to this change (since path resolution was implemented), having self in a pattern would just result in no matches.
* SSR: Restrict to current selection if anyDavid Lattimore2020-07-291-1/+10
| | | | | The selection is also used to avoid unnecessary work, but only to the file level. Further restricting unnecessary work is left for later.
* SSR: Move more resolution-related code into the resolving moduleDavid Lattimore2020-07-261-21/+5
|
* SSR: Allow function calls to match method callsDavid Lattimore2020-07-241-2/+6
| | | | | | | | | | | This differs from how this used to work before I removed it in that: a) It's only one direction. Function calls in the pattern can match method calls in the code, but not the other way around. b) We now check that the function call in the pattern resolves to the same function as the method call in the code. The lack of (b) was the reason I felt the need to remove the feature before.
* SSR: Use Definition::find_usages to speed up matching.David Lattimore2020-07-241-1/+2
| | | | When the search pattern contains a path, this substantially speeds up finding matches, especially if the path references a private item.
* SSR: Match paths based on what they resolve toDavid Lattimore2020-07-241-17/+44
| | | | Also render template paths appropriately for their context.
* SSR: Pass current file position through to SSR code.David Lattimore2020-07-241-2/+28
| | | | In a subsequent commit, it will be used for resolving paths.
* SSR: Refactor to not rely on recursive search for nesting of matchesDavid Lattimore2020-07-241-2/+5
| | | | | | | | | Previously, submatches were handled simply by searching in placeholders for more matches. That only works if we search all nodes in the tree recursively. In a subsequent commit, I intend to make search not always be recursive recursive. This commit prepares for that by finding all matches, even if they overlap, then nesting them and removing overlapping matches.
* Move iteration over all files into the SSR crateDavid Lattimore2020-07-241-21/+27
| | | | The methods `edits_for_file` and `find_matches_in_file` are replaced with just `edits` and `matches`. This simplifies the API a bit, but more importantly it makes it possible in a subsequent commit for SSR to decide to not search all files.
* SSR: Move search code into a submoduleDavid Lattimore2020-07-241-48/+2
| | | | | | Also renamed find_matches to slow_scan_node to reflect that it's a slow way to do things. Actually the name came from a later commit and probably makes more sense once there's an alternative.
* SSR: Parse template as Rust code.David Lattimore2020-07-241-6/+8
| | | | | | This is in preparation for a subsequent commit where we add special handling for paths in the template, allowing them to be qualified differently in different contexts.
* SSR: Change the way rules are stored internally.David Lattimore2020-07-241-43/+33
| | | | | | | | | | | | | | | | | | | | | | Previously we had: - Multiple rules - Each rule had its pattern parsed as an expression, path etc This meant that there were two levels at which there could be multiple rules. Now we just have multiple rules. If a pattern can parse as more than one kind of thing, then they get stored as multiple separate rules. We also now don't have separate fields for the different kinds of things that a pattern can parse as. This makes adding new kinds of things simpler. Previously, add_search_pattern would construct a rule with a dummy replacement. Now the replacement is an Option. This is slightly cleaner and also opens the way for parsing the replacement template as the same kind of thing as the search pattern.
* SSR: Improve error reporting when a test failsDavid Lattimore2020-07-031-15/+15
|
* SSR: Extract error code out to a separate moduleDavid Lattimore2020-07-031-9/+3
| | | | | This is to make reusing it outside of parsing easier in a subsequent change.
* Structured search debuggingDavid Lattimore2020-07-011-5/+157
|
* Fix handling of whitespace when applying SSR within macro expansions.David Lattimore2020-06-271-1/+2
| | | | I originally did replacement by passing in the full file text. Then as some point I thought I could do without it. Turns out calling .text() on a node coming from a macro expansion isn't a great idea, especially when you then try and use ranges from the original source to cut that text. The test I added here actually panics without the rest of this change (sorry I didn't notice sooner).
* SSR: Allow matching within macro callsDavid Lattimore2020-06-271-1/+17
|
* SSR: Allow matching of whole macro callsDavid Lattimore2020-06-221-8/+10
| | | | Matching within macro calls is to come later and matching of macro calls within macro calls later still.
* Allow SSR to match type references, items, paths and patternsDavid Lattimore2020-06-221-0/+120
Part of #3186