aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_assists')
-rw-r--r--crates/ra_assists/src/assist_context.rs13
-rw-r--r--crates/ra_assists/src/handlers/extract_struct_from_enum_variant.rs16
2 files changed, 14 insertions, 15 deletions
diff --git a/crates/ra_assists/src/assist_context.rs b/crates/ra_assists/src/assist_context.rs
index e7220eea9..94286b497 100644
--- a/crates/ra_assists/src/assist_context.rs
+++ b/crates/ra_assists/src/assist_context.rs
@@ -292,13 +292,12 @@ impl AssistBuilder {
292} 292}
293 293
294pub(crate) struct AssistDirector { 294pub(crate) struct AssistDirector {
295 source_changes: Vec<SourceChange>,
296 builders: FxHashMap<FileId, AssistBuilder>, 295 builders: FxHashMap<FileId, AssistBuilder>,
297} 296}
298 297
299impl AssistDirector { 298impl AssistDirector {
300 fn new() -> AssistDirector { 299 fn new() -> AssistDirector {
301 AssistDirector { source_changes: vec![], builders: FxHashMap::default() } 300 AssistDirector { builders: FxHashMap::default() }
302 } 301 }
303 302
304 pub(crate) fn perform(&mut self, file_id: FileId, f: impl FnOnce(&mut AssistBuilder)) { 303 pub(crate) fn perform(&mut self, file_id: FileId, f: impl FnOnce(&mut AssistBuilder)) {
@@ -306,10 +305,10 @@ impl AssistDirector {
306 f(&mut builder); 305 f(&mut builder);
307 } 306 }
308 307
309 fn finish(mut self) -> Vec<SourceChange> { 308 fn finish(self) -> Vec<SourceChange> {
310 for (_, builder) in self.builders.into_iter().collect::<Vec<(FileId, AssistBuilder)>>() { 309 self.builders
311 self.source_changes.push(builder.finish()); 310 .into_iter()
312 } 311 .map(|(_, builder)| builder.finish())
313 self.source_changes 312 .collect::<Vec<SourceChange>>()
314 } 313 }
315} 314}
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 57907a503..3250eed5b 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
@@ -59,8 +59,8 @@ pub(crate) fn extract_struct_from_enum(acc: &mut Assists, ctx: &AssistContext) -
59 let res = definition.find_usages(&ctx.db, None); 59 let res = definition.find_usages(&ctx.db, None);
60 let module_def = mod_def_for_target_module(ctx, &enum_name); 60 let module_def = mod_def_for_target_module(ctx, &enum_name);
61 let start_offset = variant.parent_enum().syntax().text_range().start(); 61 let start_offset = variant.parent_enum().syntax().text_range().start();
62 let mut seen_files_map: FxHashSet<Module> = FxHashSet::default(); 62 let mut visited_modules_set: FxHashSet<Module> = FxHashSet::default();
63 seen_files_map.insert(module_def.module(ctx.db).unwrap()); 63 visited_modules_set.insert(module_def.module(ctx.db).unwrap());
64 for reference in res { 64 for reference in res {
65 let source_file = ctx.sema.parse(reference.file_range.file_id); 65 let source_file = ctx.sema.parse(reference.file_range.file_id);
66 update_reference( 66 update_reference(
@@ -69,7 +69,7 @@ pub(crate) fn extract_struct_from_enum(acc: &mut Assists, ctx: &AssistContext) -
69 reference, 69 reference,
70 &source_file, 70 &source_file,
71 &module_def, 71 &module_def,
72 &mut seen_files_map, 72 &mut visited_modules_set,
73 ); 73 );
74 } 74 }
75 extract_struct_def( 75 extract_struct_def(
@@ -101,7 +101,7 @@ fn mod_def_for_target_module(ctx: &AssistContext, enum_name: &str) -> ModuleDef
101 ImportsLocator::new(ctx.db).find_imports(enum_name).first().unwrap().left().unwrap() 101 ImportsLocator::new(ctx.db).find_imports(enum_name).first().unwrap().left().unwrap()
102} 102}
103 103
104fn insert_use_import( 104fn insert_import(
105 ctx: &AssistContext, 105 ctx: &AssistContext,
106 builder: &mut AssistBuilder, 106 builder: &mut AssistBuilder,
107 path: &ast::PathExpr, 107 path: &ast::PathExpr,
@@ -179,7 +179,7 @@ fn update_reference(
179 reference: Reference, 179 reference: Reference,
180 source_file: &SourceFile, 180 source_file: &SourceFile,
181 module_def: &ModuleDef, 181 module_def: &ModuleDef,
182 seen_files_map: &mut FxHashSet<Module>, 182 visited_modules_set: &mut FxHashSet<Module>,
183) -> Option<()> { 183) -> Option<()> {
184 let path_expr: ast::PathExpr = find_node_at_offset::<ast::PathExpr>( 184 let path_expr: ast::PathExpr = find_node_at_offset::<ast::PathExpr>(
185 source_file.syntax(), 185 source_file.syntax(),
@@ -195,8 +195,8 @@ fn update_reference(
195 ); 195 );
196 edit.perform(reference.file_range.file_id, |builder| { 196 edit.perform(reference.file_range.file_id, |builder| {
197 let module = ctx.sema.scope(&path_expr.syntax()).module().unwrap(); 197 let module = ctx.sema.scope(&path_expr.syntax()).module().unwrap();
198 if !seen_files_map.contains(&module) { 198 if !visited_modules_set.contains(&module) {
199 if insert_use_import( 199 if insert_import(
200 ctx, 200 ctx,
201 builder, 201 builder,
202 &path_expr, 202 &path_expr,
@@ -206,7 +206,7 @@ fn update_reference(
206 ) 206 )
207 .is_some() 207 .is_some()
208 { 208 {
209 seen_files_map.insert(module); 209 visited_modules_set.insert(module);
210 } 210 }
211 } 211 }
212 builder.replace(inside_list_range, format!("{}{}", segment, list)); 212 builder.replace(inside_list_range, format!("{}{}", segment, list));