aboutsummaryrefslogtreecommitdiff
path: root/crates/ssr
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ssr')
-rw-r--r--crates/ssr/src/lib.rs36
-rw-r--r--crates/ssr/src/matching.rs2
-rw-r--r--crates/ssr/src/tests.rs2
3 files changed, 18 insertions, 22 deletions
diff --git a/crates/ssr/src/lib.rs b/crates/ssr/src/lib.rs
index d99ebefb1..a97fc8bca 100644
--- a/crates/ssr/src/lib.rs
+++ b/crates/ssr/src/lib.rs
@@ -74,13 +74,11 @@ pub use crate::errors::SsrError;
74pub use crate::matching::Match; 74pub use crate::matching::Match;
75use crate::matching::MatchFailureReason; 75use crate::matching::MatchFailureReason;
76use hir::Semantics; 76use hir::Semantics;
77use ide_db::{ 77use ide_db::base_db::{FileId, FilePosition, FileRange};
78 base_db::{FileId, FilePosition, FileRange},
79 source_change::SourceFileEdits,
80};
81use resolving::ResolvedRule; 78use resolving::ResolvedRule;
82use rustc_hash::FxHashMap; 79use rustc_hash::FxHashMap;
83use syntax::{ast, AstNode, SyntaxNode, TextRange}; 80use syntax::{ast, AstNode, SyntaxNode, TextRange};
81use text_edit::TextEdit;
84 82
85// A structured search replace rule. Create by calling `parse` on a str. 83// A structured search replace rule. Create by calling `parse` on a str.
86#[derive(Debug)] 84#[derive(Debug)]
@@ -161,7 +159,7 @@ impl<'db> MatchFinder<'db> {
161 } 159 }
162 160
163 /// Finds matches for all added rules and returns edits for all found matches. 161 /// Finds matches for all added rules and returns edits for all found matches.
164 pub fn edits(&self) -> SourceFileEdits { 162 pub fn edits(&self) -> FxHashMap<FileId, TextEdit> {
165 use ide_db::base_db::SourceDatabaseExt; 163 use ide_db::base_db::SourceDatabaseExt;
166 let mut matches_by_file = FxHashMap::default(); 164 let mut matches_by_file = FxHashMap::default();
167 for m in self.matches().matches { 165 for m in self.matches().matches {
@@ -171,21 +169,19 @@ impl<'db> MatchFinder<'db> {
171 .matches 169 .matches
172 .push(m); 170 .push(m);
173 } 171 }
174 SourceFileEdits { 172 matches_by_file
175 edits: matches_by_file 173 .into_iter()
176 .into_iter() 174 .map(|(file_id, matches)| {
177 .map(|(file_id, matches)| { 175 (
178 ( 176 file_id,
179 file_id, 177 replacing::matches_to_edit(
180 replacing::matches_to_edit( 178 &matches,
181 &matches, 179 &self.sema.db.file_text(file_id),
182 &self.sema.db.file_text(file_id), 180 &self.rules,
183 &self.rules, 181 ),
184 ), 182 )
185 ) 183 })
186 }) 184 .collect()
187 .collect(),
188 }
189 } 185 }
190 186
191 /// Adds a search pattern. For use if you intend to only call `find_matches_in_file`. If you 187 /// Adds a search pattern. For use if you intend to only call `find_matches_in_file`. If you
diff --git a/crates/ssr/src/matching.rs b/crates/ssr/src/matching.rs
index 5888bf8f8..42d313f91 100644
--- a/crates/ssr/src/matching.rs
+++ b/crates/ssr/src/matching.rs
@@ -810,7 +810,7 @@ mod tests {
810 810
811 let edits = match_finder.edits(); 811 let edits = match_finder.edits();
812 assert_eq!(edits.len(), 1); 812 assert_eq!(edits.len(), 1);
813 let edit = &edits.edits[&position.file_id]; 813 let edit = &edits[&position.file_id];
814 let mut after = input.to_string(); 814 let mut after = input.to_string();
815 edit.apply(&mut after); 815 edit.apply(&mut after);
816 assert_eq!(after, "fn foo() {} fn bar() {} fn main() { bar(1+2); }"); 816 assert_eq!(after, "fn foo() {} fn bar() {} fn main() { bar(1+2); }");
diff --git a/crates/ssr/src/tests.rs b/crates/ssr/src/tests.rs
index 8ba783526..a3ea44f23 100644
--- a/crates/ssr/src/tests.rs
+++ b/crates/ssr/src/tests.rs
@@ -106,7 +106,7 @@ fn assert_ssr_transforms(rules: &[&str], input: &str, expected: Expect) {
106 // Note, db.file_text is not necessarily the same as `input`, since fixture parsing alters 106 // Note, db.file_text is not necessarily the same as `input`, since fixture parsing alters
107 // stuff. 107 // stuff.
108 let mut actual = db.file_text(position.file_id).to_string(); 108 let mut actual = db.file_text(position.file_id).to_string();
109 edits.edits[&position.file_id].apply(&mut actual); 109 edits[&position.file_id].apply(&mut actual);
110 expected.assert_eq(&actual); 110 expected.assert_eq(&actual);
111} 111}
112 112