diff options
Diffstat (limited to 'crates/ssr/src/lib.rs')
-rw-r--r-- | crates/ssr/src/lib.rs | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/crates/ssr/src/lib.rs b/crates/ssr/src/lib.rs index 747ce495d..a97fc8bca 100644 --- a/crates/ssr/src/lib.rs +++ b/crates/ssr/src/lib.rs | |||
@@ -75,10 +75,10 @@ pub use crate::matching::Match; | |||
75 | use crate::matching::MatchFailureReason; | 75 | use crate::matching::MatchFailureReason; |
76 | use hir::Semantics; | 76 | use hir::Semantics; |
77 | use ide_db::base_db::{FileId, FilePosition, FileRange}; | 77 | use ide_db::base_db::{FileId, FilePosition, FileRange}; |
78 | use ide_db::source_change::SourceFileEdit; | ||
79 | use resolving::ResolvedRule; | 78 | use resolving::ResolvedRule; |
80 | use rustc_hash::FxHashMap; | 79 | use rustc_hash::FxHashMap; |
81 | use syntax::{ast, AstNode, SyntaxNode, TextRange}; | 80 | use syntax::{ast, AstNode, SyntaxNode, TextRange}; |
81 | use text_edit::TextEdit; | ||
82 | 82 | ||
83 | // 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. |
84 | #[derive(Debug)] | 84 | #[derive(Debug)] |
@@ -159,7 +159,7 @@ impl<'db> MatchFinder<'db> { | |||
159 | } | 159 | } |
160 | 160 | ||
161 | /// 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. |
162 | pub fn edits(&self) -> Vec<SourceFileEdit> { | 162 | pub fn edits(&self) -> FxHashMap<FileId, TextEdit> { |
163 | use ide_db::base_db::SourceDatabaseExt; | 163 | use ide_db::base_db::SourceDatabaseExt; |
164 | let mut matches_by_file = FxHashMap::default(); | 164 | let mut matches_by_file = FxHashMap::default(); |
165 | for m in self.matches().matches { | 165 | for m in self.matches().matches { |
@@ -169,13 +169,19 @@ impl<'db> MatchFinder<'db> { | |||
169 | .matches | 169 | .matches |
170 | .push(m); | 170 | .push(m); |
171 | } | 171 | } |
172 | let mut edits = vec![]; | 172 | matches_by_file |
173 | for (file_id, matches) in matches_by_file { | 173 | .into_iter() |
174 | let edit = | 174 | .map(|(file_id, matches)| { |
175 | replacing::matches_to_edit(&matches, &self.sema.db.file_text(file_id), &self.rules); | 175 | ( |
176 | edits.push(SourceFileEdit { file_id, edit }); | 176 | file_id, |
177 | } | 177 | replacing::matches_to_edit( |
178 | edits | 178 | &matches, |
179 | &self.sema.db.file_text(file_id), | ||
180 | &self.rules, | ||
181 | ), | ||
182 | ) | ||
183 | }) | ||
184 | .collect() | ||
179 | } | 185 | } |
180 | 186 | ||
181 | /// 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 |