diff options
author | David Lattimore <[email protected]> | 2020-07-22 07:23:43 +0100 |
---|---|---|
committer | David Lattimore <[email protected]> | 2020-07-24 12:34:00 +0100 |
commit | a45682ed96f18f962ac403419b4d143d59ba5283 (patch) | |
tree | 5f2178b2957b2e7cfddac94ec1748edb3dd19f10 /crates/ra_ssr/src/matching.rs | |
parent | 13f901f636846e330699a4414059591ec2e67cd1 (diff) |
Move iteration over all files into the SSR crate
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.
Diffstat (limited to 'crates/ra_ssr/src/matching.rs')
-rw-r--r-- | crates/ra_ssr/src/matching.rs | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/crates/ra_ssr/src/matching.rs b/crates/ra_ssr/src/matching.rs index 486191635..064e3a204 100644 --- a/crates/ra_ssr/src/matching.rs +++ b/crates/ra_ssr/src/matching.rs | |||
@@ -570,13 +570,12 @@ mod tests { | |||
570 | #[test] | 570 | #[test] |
571 | fn parse_match_replace() { | 571 | fn parse_match_replace() { |
572 | let rule: SsrRule = "foo($x) ==>> bar($x)".parse().unwrap(); | 572 | let rule: SsrRule = "foo($x) ==>> bar($x)".parse().unwrap(); |
573 | let input = "fn foo() {} fn main() { foo(1+2); }"; | 573 | let input = "fn foo() {} fn bar() {} fn main() { foo(1+2); }"; |
574 | 574 | ||
575 | use ra_db::fixture::WithFixture; | 575 | let (db, _) = crate::tests::single_file(input); |
576 | let (db, file_id) = ra_ide_db::RootDatabase::with_single_file(input); | ||
577 | let mut match_finder = MatchFinder::new(&db); | 576 | let mut match_finder = MatchFinder::new(&db); |
578 | match_finder.add_rule(rule); | 577 | match_finder.add_rule(rule); |
579 | let matches = match_finder.find_matches_in_file(file_id); | 578 | let matches = match_finder.matches(); |
580 | assert_eq!(matches.matches.len(), 1); | 579 | assert_eq!(matches.matches.len(), 1); |
581 | assert_eq!(matches.matches[0].matched_node.text(), "foo(1+2)"); | 580 | assert_eq!(matches.matches[0].matched_node.text(), "foo(1+2)"); |
582 | assert_eq!(matches.matches[0].placeholder_values.len(), 1); | 581 | assert_eq!(matches.matches[0].placeholder_values.len(), 1); |
@@ -589,9 +588,11 @@ mod tests { | |||
589 | "1+2" | 588 | "1+2" |
590 | ); | 589 | ); |
591 | 590 | ||
592 | let edit = crate::replacing::matches_to_edit(&matches, input, &match_finder.rules); | 591 | let edits = match_finder.edits(); |
592 | assert_eq!(edits.len(), 1); | ||
593 | let edit = &edits[0]; | ||
593 | let mut after = input.to_string(); | 594 | let mut after = input.to_string(); |
594 | edit.apply(&mut after); | 595 | edit.edit.apply(&mut after); |
595 | assert_eq!(after, "fn foo() {} fn main() { bar(1+2); }"); | 596 | assert_eq!(after, "fn foo() {} fn bar() {} fn main() { bar(1+2); }"); |
596 | } | 597 | } |
597 | } | 598 | } |