1
1
use ide_db:: {
2
2
assists:: { AssistId , AssistKind } ,
3
3
defs:: Definition ,
4
- search:: { FileReference , SearchScope , UsageSearchResult } ,
4
+ search:: { FileReference , SearchScope } ,
5
5
syntax_helpers:: suggest_name,
6
6
text_edit:: TextRange ,
7
7
} ;
@@ -124,22 +124,25 @@ fn collect_data(ident_pat: IdentPat, ctx: &AssistContext<'_>) -> Option<TupleDat
124
124
return None ;
125
125
}
126
126
127
- let name = ident_pat. name ( ) ?. to_string ( ) ;
128
-
129
- let usages = ctx. sema . to_def ( & ident_pat) . map ( |def| {
127
+ let usages = ctx. sema . to_def ( & ident_pat) . and_then ( |def| {
130
128
Definition :: Local ( def)
131
129
. usages ( & ctx. sema )
132
130
. in_scope ( & SearchScope :: single_file ( ctx. file_id ( ) ) )
133
131
. all ( )
132
+ . iter ( )
133
+ . next ( )
134
+ . map ( |( _, refs) | refs. to_vec ( ) )
134
135
} ) ;
135
136
136
137
let mut name_generator = {
137
138
let mut names = vec ! [ ] ;
138
- ctx. sema . scope ( ident_pat. syntax ( ) ) ?. process_all_names ( & mut |name, scope| {
139
- if let hir:: ScopeDef :: Local ( _) = scope {
140
- names. push ( name. as_str ( ) . into ( ) )
141
- }
142
- } ) ;
139
+ if let Some ( scope) = ctx. sema . scope ( ident_pat. syntax ( ) ) {
140
+ scope. process_all_names ( & mut |name, scope| {
141
+ if let hir:: ScopeDef :: Local ( _) = scope {
142
+ names. push ( name. as_str ( ) . into ( ) )
143
+ }
144
+ } )
145
+ }
143
146
suggest_name:: NameGenerator :: new_with_names ( names. iter ( ) . map ( |s : & SmolStr | s. as_str ( ) ) )
144
147
} ;
145
148
@@ -166,7 +169,7 @@ struct TupleData {
166
169
ident_pat : IdentPat ,
167
170
ref_type : Option < RefType > ,
168
171
field_names : Vec < String > ,
169
- usages : Option < UsageSearchResult > ,
172
+ usages : Option < Vec < FileReference > > ,
170
173
}
171
174
fn edit_tuple_assignment (
172
175
ctx : & AssistContext < ' _ > ,
@@ -222,42 +225,23 @@ fn edit_tuple_usages(
222
225
ctx : & AssistContext < ' _ > ,
223
226
in_sub_pattern : bool ,
224
227
) -> Option < Vec < EditTupleUsage > > {
225
- let mut current_file_usages = None ;
226
-
227
- if let Some ( usages) = data. usages . as_ref ( ) {
228
- // We need to collect edits first before actually applying them
229
- // as mapping nodes to their mutable node versions requires an
230
- // unmodified syntax tree.
231
- //
232
- // We also defer editing usages in the current file first since
233
- // tree mutation in the same file breaks when `builder.edit_file`
234
- // is called
235
-
236
- if let Some ( ( _, refs) ) = usages. iter ( ) . find ( |( file_id, _) | * file_id == ctx. file_id ( ) ) {
237
- current_file_usages = Some (
238
- refs. iter ( )
239
- . filter_map ( |r| edit_tuple_usage ( ctx, edit, r, data, in_sub_pattern) )
240
- . collect_vec ( ) ,
241
- ) ;
242
- }
243
-
244
- for ( file_id, refs) in usages. iter ( ) {
245
- if file_id == ctx. file_id ( ) {
246
- continue ;
247
- }
248
-
249
- edit. edit_file ( file_id. file_id ( ) ) ;
250
-
251
- let tuple_edits = refs
252
- . iter ( )
253
- . filter_map ( |r| edit_tuple_usage ( ctx, edit, r, data, in_sub_pattern) )
254
- . collect_vec ( ) ;
255
-
256
- tuple_edits. into_iter ( ) . for_each ( |tuple_edit| tuple_edit. apply ( edit) )
257
- }
258
- }
259
-
260
- current_file_usages
228
+ // We need to collect edits first before actually applying them
229
+ // as mapping nodes to their mutable node versions requires an
230
+ // unmodified syntax tree.
231
+ //
232
+ // We also defer editing usages in the current file first since
233
+ // tree mutation in the same file breaks when `builder.edit_file`
234
+ // is called
235
+
236
+ let edits = data
237
+ . usages
238
+ . as_ref ( ) ?
239
+ . as_slice ( )
240
+ . iter ( )
241
+ . filter_map ( |r| edit_tuple_usage ( ctx, edit, r, data, in_sub_pattern) )
242
+ . collect_vec ( ) ;
243
+
244
+ Some ( edits)
261
245
}
262
246
fn edit_tuple_usage (
263
247
ctx : & AssistContext < ' _ > ,
0 commit comments