aboutsummaryrefslogtreecommitdiff
path: root/crates/ssr/src/lib.rs
diff options
context:
space:
mode:
authorLukas Wirth <[email protected]>2021-01-14 21:43:36 +0000
committerLukas Wirth <[email protected]>2021-01-14 21:43:36 +0000
commitd5095329a1c12e93653d8de4a93f0b4f5cad4c6e (patch)
tree1de73ddefe48cc9f82cb4f063eaddc069adf83bc /crates/ssr/src/lib.rs
parente23bfafb32a235fdb60ba279ea68b5aa381c2110 (diff)
Phase out SourceFileEdits in favour of a plain HashMap
Diffstat (limited to 'crates/ssr/src/lib.rs')
-rw-r--r--crates/ssr/src/lib.rs36
1 files changed, 16 insertions, 20 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