Skip to content

Commit 252ec7f

Browse files
committed
fix: adjust name of extract_type_alias
Example --- **Before this PR** ```rust type $0Type = (u8, u8, u8); struct S { field: Type } ``` **After this PR** ```rust type $0ExtractedType = (u8, u8, u8); struct S { field: ExtractedType } ```
1 parent 26d7ba3 commit 252ec7f

2 files changed

Lines changed: 30 additions & 29 deletions

File tree

crates/ide-assists/src/handlers/extract_type_alias.rs

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ use crate::{AssistContext, AssistId, Assists};
1919
// ```
2020
// ->
2121
// ```
22-
// type $0Type = (u8, u8, u8);
22+
// type $0ExtractedType = (u8, u8, u8);
2323
//
2424
// struct S {
25-
// field: Type,
25+
// field: ExtractedType,
2626
// }
2727
// ```
2828
pub(crate) fn extract_type_alias(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
@@ -57,6 +57,7 @@ pub(crate) fn extract_type_alias(acc: &mut Assists, ctx: &AssistContext<'_>) ->
5757
let make = editor.make();
5858

5959
let resolved_ty = make.ty(&resolved_ty);
60+
let name = "ExtractedType";
6061

6162
let mut known_generics = match item.generic_param_list() {
6263
Some(it) => it.generic_params().collect(),
@@ -75,15 +76,15 @@ pub(crate) fn extract_type_alias(acc: &mut Assists, ctx: &AssistContext<'_>) ->
7576
// Replace original type with the alias
7677
let ty_args = generic_params.as_ref().map(|it| it.to_generic_args().generic_args());
7778
let new_ty = if let Some(ty_args) = ty_args {
78-
make.generic_ty_path_segment(make.name_ref("Type"), ty_args)
79+
make.generic_ty_path_segment(make.name_ref(name), ty_args)
7980
} else {
80-
make.path_segment(make.name_ref("Type"))
81+
make.path_segment(make.name_ref(name))
8182
};
8283
editor.replace(ty.syntax(), new_ty.syntax());
8384

8485
// Insert new alias
8586
let ty_alias =
86-
make.ty_alias(None, "Type", generic_params, None, None, Some((resolved_ty, None)));
87+
make.ty_alias(None, name, generic_params, None, None, Some((resolved_ty, None)));
8788

8889
if let Some(cap) = ctx.config.snippet_cap
8990
&& let Some(name) = ty_alias.name()
@@ -229,10 +230,10 @@ struct S {
229230
}
230231
",
231232
r#"
232-
type $0Type = u8;
233+
type $0ExtractedType = u8;
233234
234235
struct S {
235-
field: Type,
236+
field: ExtractedType,
236237
}
237238
"#,
238239
);
@@ -252,10 +253,10 @@ fn f() {
252253
r#"
253254
fn generic<T>() {}
254255
255-
type $0Type = ();
256+
type $0ExtractedType = ();
256257
257258
fn f() {
258-
generic::<Type>();
259+
generic::<ExtractedType>();
259260
}
260261
"#,
261262
);
@@ -273,10 +274,10 @@ struct S {
273274
",
274275
r#"
275276
struct Vec<T> {}
276-
type $0Type = Vec<u8>;
277+
type $0ExtractedType = Vec<u8>;
277278
278279
struct S {
279-
v: Vec<Vec<Type>>,
280+
v: Vec<Vec<ExtractedType>>,
280281
}
281282
"#,
282283
);
@@ -292,10 +293,10 @@ struct S {
292293
}
293294
",
294295
r#"
295-
type $0Type = u8;
296+
type $0ExtractedType = u8;
296297
297298
struct S {
298-
field: (Type,),
299+
field: (ExtractedType,),
299300
}
300301
"#,
301302
);
@@ -313,10 +314,10 @@ impl S {
313314
}
314315
"#,
315316
r#"
316-
type $0Type = (u8, u8);
317+
type $0ExtractedType = (u8, u8);
317318
318319
impl S {
319-
fn f() -> Type {}
320+
fn f() -> ExtractedType {}
320321
}
321322
"#,
322323
);
@@ -328,10 +329,10 @@ trait Tr {
328329
}
329330
"#,
330331
r#"
331-
type $0Type = (u8, u8);
332+
type $0ExtractedType = (u8, u8);
332333
333334
trait Tr {
334-
fn f() -> Type {}
335+
fn f() -> ExtractedType {}
335336
}
336337
"#,
337338
);
@@ -348,9 +349,9 @@ mod m {
348349
"#,
349350
r#"
350351
mod m {
351-
type $0Type = u8;
352+
type $0ExtractedType = u8;
352353
353-
fn f() -> Type {}
354+
fn f() -> ExtractedType {}
354355
}
355356
"#,
356357
);
@@ -368,10 +369,10 @@ impl<'outer, Outer, const OUTER: usize> () {
368369
"#,
369370
r#"
370371
struct Struct<const C: usize>;
371-
type $0Type<'inner, 'outer, Outer, Inner, const INNER: usize, const OUTER: usize> = &(Struct<INNER>, Struct<OUTER>, Outer, &'inner (), Inner, &'outer ());
372+
type $0ExtractedType<'inner, 'outer, Outer, Inner, const INNER: usize, const OUTER: usize> = &(Struct<INNER>, Struct<OUTER>, Outer, &'inner (), Inner, &'outer ());
372373
373374
impl<'outer, Outer, const OUTER: usize> () {
374-
fn func<'inner, Inner, const INNER: usize>(_: Type<'inner, 'outer, Outer, Inner, INNER, OUTER>) {}
375+
fn func<'inner, Inner, const INNER: usize>(_: ExtractedType<'inner, 'outer, Outer, Inner, INNER, OUTER>) {}
375376
}
376377
"#,
377378
);
@@ -390,13 +391,13 @@ where
390391
}
391392
"#,
392393
r#"
393-
type $0Type<T, const N: usize> = [T; N];
394+
type $0ExtractedType<T, const N: usize> = [T; N];
394395
395396
struct Foo<T, const N: usize>
396397
where
397398
[T; N]: Sized,
398399
{
399-
arr: Type<T, N>,
400+
arr: ExtractedType<T, N>,
400401
}
401402
"#,
402403
);
@@ -416,10 +417,10 @@ fn main() {
416417
r#"
417418
struct Wrap<T>(T);
418419
419-
type $0Type = Wrap<i32>;
420+
type $0ExtractedType = Wrap<i32>;
420421
421422
fn main() {
422-
let wrap: Type = Wrap::<_>(3i32);
423+
let wrap: ExtractedType = Wrap::<_>(3i32);
423424
}
424425
"#,
425426
)
@@ -439,10 +440,10 @@ fn main() {
439440
r#"
440441
struct Wrap<T>(T);
441442
442-
type $0Type = i32;
443+
type $0ExtractedType = i32;
443444
444445
fn main() {
445-
let wrap: Wrap<Type> = Wrap::<_>(3i32);
446+
let wrap: Wrap<ExtractedType> = Wrap::<_>(3i32);
446447
}
447448
"#,
448449
)

crates/ide-assists/src/tests/generated.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,10 +1327,10 @@ struct S {
13271327
}
13281328
"#####,
13291329
r#####"
1330-
type $0Type = (u8, u8, u8);
1330+
type $0ExtractedType = (u8, u8, u8);
13311331
13321332
struct S {
1333-
field: Type,
1333+
field: ExtractedType,
13341334
}
13351335
"#####,
13361336
)

0 commit comments

Comments
 (0)