aboutsummaryrefslogtreecommitdiff
path: root/crates/assists/src/handlers
diff options
context:
space:
mode:
Diffstat (limited to 'crates/assists/src/handlers')
-rw-r--r--crates/assists/src/handlers/extract_struct_from_enum_variant.rs6
-rw-r--r--crates/assists/src/handlers/inline_local_variable.rs14
-rw-r--r--crates/assists/src/handlers/remove_unused_param.rs18
3 files changed, 18 insertions, 20 deletions
diff --git a/crates/assists/src/handlers/extract_struct_from_enum_variant.rs b/crates/assists/src/handlers/extract_struct_from_enum_variant.rs
index 21b13977b..e3ef04932 100644
--- a/crates/assists/src/handlers/extract_struct_from_enum_variant.rs
+++ b/crates/assists/src/handlers/extract_struct_from_enum_variant.rs
@@ -8,7 +8,7 @@ use ide_db::{
8 insert_use::{insert_use, ImportScope}, 8 insert_use::{insert_use, ImportScope},
9 mod_path_to_ast, 9 mod_path_to_ast,
10 }, 10 },
11 search::{FileReference, FileReferences}, 11 search::FileReference,
12 RootDatabase, 12 RootDatabase,
13}; 13};
14use rustc_hash::FxHashSet; 14use rustc_hash::FxHashSet;
@@ -63,10 +63,10 @@ pub(crate) fn extract_struct_from_enum_variant(
63 let current_module = enum_hir.module(ctx.db()); 63 let current_module = enum_hir.module(ctx.db());
64 visited_modules_set.insert(current_module); 64 visited_modules_set.insert(current_module);
65 let mut def_rewriter = None; 65 let mut def_rewriter = None;
66 for FileReferences { file_id, references: refs } in usages { 66 for (file_id, references) in usages {
67 let mut rewriter = SyntaxRewriter::default(); 67 let mut rewriter = SyntaxRewriter::default();
68 let source_file = ctx.sema.parse(file_id); 68 let source_file = ctx.sema.parse(file_id);
69 for reference in refs { 69 for reference in references {
70 update_reference( 70 update_reference(
71 ctx, 71 ctx,
72 &mut rewriter, 72 &mut rewriter,
diff --git a/crates/assists/src/handlers/inline_local_variable.rs b/crates/assists/src/handlers/inline_local_variable.rs
index 928df6825..dc798daaa 100644
--- a/crates/assists/src/handlers/inline_local_variable.rs
+++ b/crates/assists/src/handlers/inline_local_variable.rs
@@ -47,8 +47,8 @@ pub(crate) fn inline_local_variable(acc: &mut Assists, ctx: &AssistContext) -> O
47 47
48 let def = ctx.sema.to_def(&bind_pat)?; 48 let def = ctx.sema.to_def(&bind_pat)?;
49 let def = Definition::Local(def); 49 let def = Definition::Local(def);
50 let refs = def.usages(&ctx.sema).all(); 50 let usages = def.usages(&ctx.sema).all();
51 if refs.is_empty() { 51 if usages.is_empty() {
52 mark::hit!(test_not_applicable_if_variable_unused); 52 mark::hit!(test_not_applicable_if_variable_unused);
53 return None; 53 return None;
54 }; 54 };
@@ -66,9 +66,10 @@ pub(crate) fn inline_local_variable(acc: &mut Assists, ctx: &AssistContext) -> O
66 let_stmt.syntax().text_range() 66 let_stmt.syntax().text_range()
67 }; 67 };
68 68
69 let wrap_in_parens = refs 69 let wrap_in_parens = usages
70 .iter() 70 .references
71 .flat_map(|refs| &refs.references) 71 .values()
72 .flatten()
72 .map(|&FileReference { range, .. }| { 73 .map(|&FileReference { range, .. }| {
73 let usage_node = 74 let usage_node =
74 ctx.covering_node_for_range(range).ancestors().find_map(ast::PathExpr::cast)?; 75 ctx.covering_node_for_range(range).ancestors().find_map(ast::PathExpr::cast)?;
@@ -115,8 +116,7 @@ pub(crate) fn inline_local_variable(acc: &mut Assists, ctx: &AssistContext) -> O
115 target, 116 target,
116 move |builder| { 117 move |builder| {
117 builder.delete(delete_range); 118 builder.delete(delete_range);
118 for (reference, should_wrap) in 119 for (reference, should_wrap) in usages.references.values().flatten().zip(wrap_in_parens)
119 refs.iter().flat_map(|refs| &refs.references).zip(wrap_in_parens)
120 { 120 {
121 let replacement = 121 let replacement =
122 if should_wrap { init_in_paren.clone() } else { init_str.clone() }; 122 if should_wrap { init_in_paren.clone() } else { init_str.clone() };
diff --git a/crates/assists/src/handlers/remove_unused_param.rs b/crates/assists/src/handlers/remove_unused_param.rs
index 4f3b8ac46..c961680e2 100644
--- a/crates/assists/src/handlers/remove_unused_param.rs
+++ b/crates/assists/src/handlers/remove_unused_param.rs
@@ -1,7 +1,4 @@
1use ide_db::{ 1use ide_db::{base_db::FileId, defs::Definition, search::FileReference};
2 defs::Definition,
3 search::{FileReference, FileReferences},
4};
5use syntax::{ 2use syntax::{
6 algo::find_node_at_range, 3 algo::find_node_at_range,
7 ast::{self, ArgListOwner}, 4 ast::{self, ArgListOwner},
@@ -61,8 +58,8 @@ pub(crate) fn remove_unused_param(acc: &mut Assists, ctx: &AssistContext) -> Opt
61 param.syntax().text_range(), 58 param.syntax().text_range(),
62 |builder| { 59 |builder| {
63 builder.delete(range_to_remove(param.syntax())); 60 builder.delete(range_to_remove(param.syntax()));
64 for usages in fn_def.usages(&ctx.sema).all() { 61 for (file_id, references) in fn_def.usages(&ctx.sema).all() {
65 process_usages(ctx, builder, usages, param_position); 62 process_usages(ctx, builder, file_id, references, param_position);
66 } 63 }
67 }, 64 },
68 ) 65 )
@@ -71,12 +68,13 @@ pub(crate) fn remove_unused_param(acc: &mut Assists, ctx: &AssistContext) -> Opt
71fn process_usages( 68fn process_usages(
72 ctx: &AssistContext, 69 ctx: &AssistContext,
73 builder: &mut AssistBuilder, 70 builder: &mut AssistBuilder,
74 usages: FileReferences, 71 file_id: FileId,
72 references: Vec<FileReference>,
75 arg_to_remove: usize, 73 arg_to_remove: usize,
76) { 74) {
77 let source_file = ctx.sema.parse(usages.file_id); 75 let source_file = ctx.sema.parse(file_id);
78 builder.edit_file(usages.file_id); 76 builder.edit_file(file_id);
79 for usage in usages.references { 77 for usage in references {
80 if let Some(text_range) = process_usage(&source_file, usage, arg_to_remove) { 78 if let Some(text_range) = process_usage(&source_file, usage, arg_to_remove) {
81 builder.delete(text_range); 79 builder.delete(text_range);
82 } 80 }