fix: arbitary noop of assist and same file double writes
@@ -73,11 +73,6 @@ pub(crate) fn extract_module(acc: &mut Assists, ctx: &AssistContext) -> Option<(
let old_item_indent = module.body_items[0].indent_level();
- acc.add(
- AssistId("extract_module", AssistKind::RefactorExtract),
- "Extract Module",
- module.text_range,
- |builder| {
//This takes place in three steps:
//
//- Firstly, we will update the references(usages) e.g. converting a
@@ -95,13 +90,16 @@ pub(crate) fn extract_module(acc: &mut Assists, ctx: &AssistContext) -> Option<(
let (usages_to_be_processed, record_fields) = module.get_usages_and_record_fields(ctx);
let import_paths_to_be_removed = module.resolve_imports(curr_parent_module, &ctx);
-
- if let Some(block_items) = module.change_visibility(record_fields) {
- module.body_items = block_items;
+ module.body_items = module.change_visibility(record_fields)?;
if module.body_items.len() == 0 {
- return;
+ return None;
}
+ acc.add(
+ AssistId("extract_module", AssistKind::RefactorExtract),
+ "Extract Module",
+ module.text_range,
+ |builder| {
let mut body_items = Vec::new();
let new_item_indent = old_item_indent + 1;
for item in module.body_items {
@@ -117,7 +115,12 @@ pub(crate) fn extract_module(acc: &mut Assists, ctx: &AssistContext) -> Option<(
format_to!(module_def, "mod {} {{\n{}\n{}}}", module.name, body, old_item_indent);
+ let mut usages_to_be_updated_for_curr_file = vec![];
for usages_to_be_updated_for_file in usages_to_be_processed {
+ if usages_to_be_updated_for_file.0 == ctx.frange.file_id {
+ usages_to_be_updated_for_curr_file = usages_to_be_updated_for_file.1;
+ continue;
+ }
builder.edit_file(usages_to_be_updated_for_file.0);
for usage_to_be_processed in usages_to_be_updated_for_file.1 {
builder.replace(usage_to_be_processed.0, usage_to_be_processed.1)
@@ -125,11 +128,14 @@ pub(crate) fn extract_module(acc: &mut Assists, ctx: &AssistContext) -> Option<(
}
builder.edit_file(ctx.frange.file_id);
+ for usage_to_be_processed in usages_to_be_updated_for_curr_file {
+ builder.replace(usage_to_be_processed.0, usage_to_be_processed.1)
+ }
+
for import_path_text_range in import_paths_to_be_removed {
builder.delete(import_path_text_range);
}
builder.replace(module.text_range, module_def)
- }
},
)
}
