diff options
Diffstat (limited to 'crates/ssr/src/lib.rs')
-rw-r--r-- | crates/ssr/src/lib.rs | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/crates/ssr/src/lib.rs b/crates/ssr/src/lib.rs index 747ce495d..d99ebefb1 100644 --- a/crates/ssr/src/lib.rs +++ b/crates/ssr/src/lib.rs | |||
@@ -74,8 +74,10 @@ pub use crate::errors::SsrError; | |||
74 | pub use crate::matching::Match; | 74 | 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::{ |
78 | use ide_db::source_change::SourceFileEdit; | 78 | base_db::{FileId, FilePosition, FileRange}, |
79 | source_change::SourceFileEdits, | ||
80 | }; | ||
79 | use resolving::ResolvedRule; | 81 | use resolving::ResolvedRule; |
80 | use rustc_hash::FxHashMap; | 82 | use rustc_hash::FxHashMap; |
81 | use syntax::{ast, AstNode, SyntaxNode, TextRange}; | 83 | use syntax::{ast, AstNode, SyntaxNode, TextRange}; |
@@ -159,7 +161,7 @@ impl<'db> MatchFinder<'db> { | |||
159 | } | 161 | } |
160 | 162 | ||
161 | /// Finds matches for all added rules and returns edits for all found matches. | 163 | /// Finds matches for all added rules and returns edits for all found matches. |
162 | pub fn edits(&self) -> Vec<SourceFileEdit> { | 164 | pub fn edits(&self) -> SourceFileEdits { |
163 | use ide_db::base_db::SourceDatabaseExt; | 165 | use ide_db::base_db::SourceDatabaseExt; |
164 | let mut matches_by_file = FxHashMap::default(); | 166 | let mut matches_by_file = FxHashMap::default(); |
165 | for m in self.matches().matches { | 167 | for m in self.matches().matches { |
@@ -169,13 +171,21 @@ impl<'db> MatchFinder<'db> { | |||
169 | .matches | 171 | .matches |
170 | .push(m); | 172 | .push(m); |
171 | } | 173 | } |
172 | let mut edits = vec![]; | 174 | SourceFileEdits { |
173 | for (file_id, matches) in matches_by_file { | 175 | edits: matches_by_file |
174 | let edit = | 176 | .into_iter() |
175 | replacing::matches_to_edit(&matches, &self.sema.db.file_text(file_id), &self.rules); | 177 | .map(|(file_id, matches)| { |
176 | edits.push(SourceFileEdit { file_id, edit }); | 178 | ( |
179 | file_id, | ||
180 | replacing::matches_to_edit( | ||
181 | &matches, | ||
182 | &self.sema.db.file_text(file_id), | ||
183 | &self.rules, | ||
184 | ), | ||
185 | ) | ||
186 | }) | ||
187 | .collect(), | ||
177 | } | 188 | } |
178 | edits | ||
179 | } | 189 | } |
180 | 190 | ||
181 | /// Adds a search pattern. For use if you intend to only call `find_matches_in_file`. If you | 191 | /// Adds a search pattern. For use if you intend to only call `find_matches_in_file`. If you |