@@ -2,7 +2,7 @@ use either::Either;
2
2
use ide_db:: syntax_helpers:: node_ext:: walk_ty;
3
3
use syntax:: {
4
4
ast:: { self , edit:: IndentLevel , make, AstNode , HasGenericArgs , HasGenericParams , HasName } ,
5
- ted ,
5
+ syntax_editor ,
6
6
} ;
7
7
8
8
use crate :: { AssistContext , AssistId , AssistKind , Assists } ;
@@ -43,9 +43,8 @@ pub(crate) fn extract_type_alias(acc: &mut Assists, ctx: &AssistContext<'_>) ->
43
43
AssistId ( "extract_type_alias" , AssistKind :: RefactorExtract ) ,
44
44
"Extract type as type alias" ,
45
45
target,
46
- |edit| {
47
- let node = edit. make_syntax_mut ( node. clone ( ) ) ;
48
- let target_ty = edit. make_mut ( ty. clone ( ) ) ;
46
+ |builder| {
47
+ let mut edit = builder. make_editor ( node) ;
49
48
50
49
let mut known_generics = match item. generic_param_list ( ) {
51
50
Some ( it) => it. generic_params ( ) . collect ( ) ,
@@ -67,25 +66,28 @@ pub(crate) fn extract_type_alias(acc: &mut Assists, ctx: &AssistContext<'_>) ->
67
66
. map_or ( String :: new ( ) , |it| it. to_generic_args ( ) . to_string ( ) ) ;
68
67
// FIXME: replace with a `ast::make` constructor
69
68
let new_ty = make:: ty ( & format ! ( "Type{ty_args}" ) ) . clone_for_update ( ) ;
70
- ted :: replace ( target_ty . syntax ( ) , new_ty. syntax ( ) ) ;
69
+ edit . replace ( ty . syntax ( ) , new_ty. syntax ( ) ) ;
71
70
72
71
// Insert new alias
73
- let indent = IndentLevel :: from_node ( & node) ;
74
72
let ty_alias = make:: ty_alias ( "Type" , generic_params, None , None , Some ( ( ty, None ) ) )
75
73
. clone_for_update ( ) ;
76
- ted:: insert_all (
77
- ted:: Position :: before ( node) ,
74
+
75
+ if let Some ( cap) = ctx. config . snippet_cap {
76
+ if let Some ( name) = ty_alias. name ( ) {
77
+ edit. add_annotation ( name. syntax ( ) , builder. make_tabstop_before ( cap) ) ;
78
+ }
79
+ }
80
+
81
+ let indent = IndentLevel :: from_node ( node) ;
82
+ edit. insert_all (
83
+ syntax_editor:: Position :: before ( node) ,
78
84
vec ! [
79
85
ty_alias. syntax( ) . clone( ) . into( ) ,
80
86
make:: tokens:: whitespace( & format!( "\n \n {indent}" ) ) . into( ) ,
81
87
] ,
82
88
) ;
83
89
84
- if let Some ( cap) = ctx. config . snippet_cap {
85
- if let Some ( name) = ty_alias. name ( ) {
86
- edit. add_tabstop_before ( cap, name) ;
87
- }
88
- }
90
+ builder. add_file_edits ( ctx. file_id ( ) , edit) ;
89
91
} ,
90
92
)
91
93
}
0 commit comments