@@ -6,6 +6,7 @@ use ide_db::{
6
6
defs:: Definition ,
7
7
helpers:: mod_path_to_ast,
8
8
imports:: insert_use:: { insert_use, ImportScope , InsertUseConfig } ,
9
+ path_transform:: PathTransform ,
9
10
search:: FileReference ,
10
11
FxHashSet , RootDatabase ,
11
12
} ;
@@ -105,6 +106,16 @@ pub(crate) fn extract_struct_from_enum_variant(
105
106
. generic_param_list ( )
106
107
. and_then ( |known_generics| extract_generic_params ( & known_generics, & field_list) ) ;
107
108
let generics = generic_params. as_ref ( ) . map ( |generics| generics. clone_for_update ( ) ) ;
109
+
110
+ // resolve GenericArg in field_list to actual type
111
+ let field_list = field_list. clone_for_update ( ) ;
112
+ if let Some ( ( target_scope, source_scope) ) =
113
+ ctx. sema . scope ( enum_ast. syntax ( ) ) . zip ( ctx. sema . scope ( field_list. syntax ( ) ) )
114
+ {
115
+ PathTransform :: generic_transformation ( & target_scope, & source_scope)
116
+ . apply ( field_list. syntax ( ) ) ;
117
+ }
118
+
108
119
let def =
109
120
create_struct_def ( variant_name. clone ( ) , & variant, & field_list, generics, & enum_ast) ;
110
121
@@ -244,31 +255,6 @@ fn create_struct_def(
244
255
// for fields without any existing visibility, use visibility of enum
245
256
let field_list: ast:: FieldList = match field_list {
246
257
Either :: Left ( field_list) => {
247
- let field_list = field_list. clone_for_update ( ) ;
248
-
249
- // replace `Self` with the enum name when construct struct def
250
- field_list
251
- . fields ( )
252
- . filter_map ( |field| match field. ty ( ) ? {
253
- ast:: Type :: PathType ( p) => Some (
254
- p. syntax ( )
255
- . descendants_with_tokens ( )
256
- . filter_map ( |it| {
257
- if it. kind ( ) == T ! [ Self ] {
258
- let type_arg =
259
- make:: type_arg ( make:: ty ( & enum_. name ( ) ?. to_string ( ) ) )
260
- . clone_for_update ( ) ;
261
- Some ( ted:: replace ( it, type_arg. syntax ( ) ) )
262
- } else {
263
- None
264
- }
265
- } )
266
- . count ( ) ,
267
- ) ,
268
- _ => None ,
269
- } )
270
- . count ( ) ;
271
-
272
258
if let Some ( vis) = & enum_vis {
273
259
field_list
274
260
. fields ( )
@@ -277,11 +263,9 @@ fn create_struct_def(
277
263
. for_each ( |it| insert_vis ( it. syntax ( ) , vis. syntax ( ) ) ) ;
278
264
}
279
265
280
- field_list. into ( )
266
+ field_list. clone ( ) . into ( )
281
267
}
282
268
Either :: Right ( field_list) => {
283
- let field_list = field_list. clone_for_update ( ) ;
284
-
285
269
if let Some ( vis) = & enum_vis {
286
270
field_list
287
271
. fields ( )
@@ -290,7 +274,7 @@ fn create_struct_def(
290
274
. for_each ( |it| insert_vis ( it. syntax ( ) , vis. syntax ( ) ) ) ;
291
275
}
292
276
293
- field_list. into ( )
277
+ field_list. clone ( ) . into ( )
294
278
}
295
279
} ;
296
280
field_list. reindent_to ( IndentLevel :: single ( ) ) ;
0 commit comments