diff options
Diffstat (limited to 'crates/ra_assists/src')
-rw-r--r-- | crates/ra_assists/src/assist_context.rs | 30 | ||||
-rw-r--r-- | crates/ra_assists/src/handlers/extract_struct_from_enum_variant.rs | 7 |
2 files changed, 21 insertions, 16 deletions
diff --git a/crates/ra_assists/src/assist_context.rs b/crates/ra_assists/src/assist_context.rs index 6291c68de..52bc7820e 100644 --- a/crates/ra_assists/src/assist_context.rs +++ b/crates/ra_assists/src/assist_context.rs | |||
@@ -2,7 +2,7 @@ | |||
2 | 2 | ||
3 | use algo::find_covering_element; | 3 | use algo::find_covering_element; |
4 | use hir::Semantics; | 4 | use hir::Semantics; |
5 | use ra_db::{FileId, FileRange, FilePosition}; | 5 | use ra_db::{FileId, FileRange}; |
6 | use ra_fmt::{leading_indent, reindent}; | 6 | use ra_fmt::{leading_indent, reindent}; |
7 | use ra_ide_db::{ | 7 | use ra_ide_db::{ |
8 | source_change::{SourceChange, SourceFileEdit}, | 8 | source_change::{SourceChange, SourceFileEdit}, |
@@ -173,16 +173,20 @@ impl Assists { | |||
173 | Some(()) | 173 | Some(()) |
174 | } | 174 | } |
175 | 175 | ||
176 | fn add_impl_multiple_files(&mut self, label: Assist, f: impl FnOnce(&mut AssistDirector)) -> Option<()> { | 176 | fn add_impl_multiple_files( |
177 | &mut self, | ||
178 | label: Assist, | ||
179 | f: impl FnOnce(&mut AssistDirector), | ||
180 | ) -> Option<()> { | ||
177 | let change_label = label.label.clone(); | 181 | let change_label = label.label.clone(); |
178 | if !self.resolve { | 182 | if !self.resolve { |
179 | return None | 183 | return None; |
180 | } | 184 | } |
181 | let mut director = AssistDirector::new(change_label.clone()); | 185 | let mut director = AssistDirector::new(change_label.clone()); |
182 | f(&mut director); | 186 | f(&mut director); |
183 | let changes = director.finish(); | 187 | let changes = director.finish(); |
184 | let file_edits: Vec<SourceFileEdit> = changes.into_iter() | 188 | let file_edits: Vec<SourceFileEdit> = |
185 | .map(|mut change| change.source_file_edits.pop().unwrap()).collect(); | 189 | changes.into_iter().map(|mut change| change.source_file_edits.pop().unwrap()).collect(); |
186 | 190 | ||
187 | let source_change = SourceChange { | 191 | let source_change = SourceChange { |
188 | source_file_edits: file_edits, | 192 | source_file_edits: file_edits, |
@@ -291,16 +295,12 @@ impl AssistBuilder { | |||
291 | pub(crate) struct AssistDirector { | 295 | pub(crate) struct AssistDirector { |
292 | source_changes: Vec<SourceChange>, | 296 | source_changes: Vec<SourceChange>, |
293 | builders: FxHashMap<FileId, AssistBuilder>, | 297 | builders: FxHashMap<FileId, AssistBuilder>, |
294 | change_label: String | 298 | change_label: String, |
295 | } | 299 | } |
296 | 300 | ||
297 | impl AssistDirector { | 301 | impl AssistDirector { |
298 | fn new(change_label: String) -> AssistDirector { | 302 | fn new(change_label: String) -> AssistDirector { |
299 | AssistDirector { | 303 | AssistDirector { source_changes: vec![], builders: FxHashMap::default(), change_label } |
300 | source_changes: vec![], | ||
301 | builders: FxHashMap::default(), | ||
302 | change_label | ||
303 | } | ||
304 | } | 304 | } |
305 | 305 | ||
306 | pub(crate) fn perform(&mut self, file_id: FileId, f: impl FnOnce(&mut AssistBuilder)) { | 306 | pub(crate) fn perform(&mut self, file_id: FileId, f: impl FnOnce(&mut AssistBuilder)) { |
@@ -309,8 +309,10 @@ impl AssistDirector { | |||
309 | } | 309 | } |
310 | 310 | ||
311 | fn finish(mut self) -> Vec<SourceChange> { | 311 | fn finish(mut self) -> Vec<SourceChange> { |
312 | for (file_id, builder) in self.builders.into_iter().collect::<Vec<(FileId, AssistBuilder)>>() { | 312 | for (file_id, builder) in |
313 | self.source_changes.push(builder.finish()); | 313 | self.builders.into_iter().collect::<Vec<(FileId, AssistBuilder)>>() |
314 | { | ||
315 | self.source_changes.push(builder.finish()); | ||
314 | } | 316 | } |
315 | self.source_changes | 317 | self.source_changes |
316 | } | 318 | } |
diff --git a/crates/ra_assists/src/handlers/extract_struct_from_enum_variant.rs b/crates/ra_assists/src/handlers/extract_struct_from_enum_variant.rs index 6e19a6feb..57907a503 100644 --- a/crates/ra_assists/src/handlers/extract_struct_from_enum_variant.rs +++ b/crates/ra_assists/src/handlers/extract_struct_from_enum_variant.rs | |||
@@ -16,9 +16,9 @@ use crate::{ | |||
16 | }; | 16 | }; |
17 | use ast::{ArgListOwner, VisibilityOwner}; | 17 | use ast::{ArgListOwner, VisibilityOwner}; |
18 | use hir::{EnumVariant, Module, ModuleDef}; | 18 | use hir::{EnumVariant, Module, ModuleDef}; |
19 | use ra_db::FileId; | ||
19 | use ra_fmt::leading_indent; | 20 | use ra_fmt::leading_indent; |
20 | use rustc_hash::FxHashSet; | 21 | use rustc_hash::FxHashSet; |
21 | use ra_db::FileId; | ||
22 | 22 | ||
23 | // Assist extract_struct_from_enum | 23 | // Assist extract_struct_from_enum |
24 | // | 24 | // |
@@ -229,7 +229,10 @@ fn list_with_visibility(list: &str) -> String { | |||
229 | #[cfg(test)] | 229 | #[cfg(test)] |
230 | mod tests { | 230 | mod tests { |
231 | 231 | ||
232 | use crate::{utils::FamousDefs, tests::{check_assist, check_assist_not_applicable}}; | 232 | use crate::{ |
233 | tests::{check_assist, check_assist_not_applicable}, | ||
234 | utils::FamousDefs, | ||
235 | }; | ||
233 | 236 | ||
234 | use super::*; | 237 | use super::*; |
235 | 238 | ||