1
- use syntax:: ast :: edit_in_place :: Indent ;
2
- use syntax :: ast :: make;
3
- use syntax :: ast :: { self , AstNode , HasName } ;
4
- use syntax :: ted ;
1
+ use syntax:: {
2
+ ast :: { self , AstNode , HasName , edit_in_place :: Indent , make} ,
3
+ syntax_editor :: Position ,
4
+ } ;
5
5
6
6
use crate :: { AssistContext , AssistId , Assists } ;
7
7
@@ -68,7 +68,7 @@ pub(crate) fn generate_asref_impl_from_borrow(
68
68
ctx : & AssistContext < ' _ > ,
69
69
) -> Option < ( ) > {
70
70
let ty = ctx. find_node_at_offset :: < ast:: Type > ( ) ?;
71
- let impl_ = ast:: Impl :: cast ( ty. syntax ( ) . parent ( ) ?) ?. clone_for_update ( ) ;
71
+ let impl_ = ast:: Impl :: cast ( ty. syntax ( ) . parent ( ) ?) ?;
72
72
let path = ast:: PathType :: cast ( impl_. trait_ ( ) ?. syntax ( ) . clone ( ) ) ?;
73
73
let indent = impl_. indent_level ( ) ;
74
74
@@ -91,16 +91,29 @@ pub(crate) fn generate_asref_impl_from_borrow(
91
91
format ! ( "Generate `{target_name}` implement from `{name}`" ) ,
92
92
target,
93
93
|edit| {
94
- ted:: replace ( name. syntax ( ) , make:: name_ref ( target_name) . syntax ( ) . clone_for_update ( ) ) ;
94
+ let mut editor = edit. make_editor ( impl_. syntax ( ) ) ;
95
+ editor. replace ( name. syntax ( ) , make:: name_ref ( target_name) . syntax ( ) . clone_for_update ( ) ) ;
95
96
96
97
if let Some ( name) = method. name ( ) {
97
- ted :: replace (
98
+ editor . replace (
98
99
name. syntax ( ) ,
99
100
make:: name ( target_method_name) . syntax ( ) . clone_for_update ( ) ,
100
101
) ;
101
102
}
102
103
103
- edit. insert ( target. start ( ) , format ! ( "$0{impl_}\n \n {indent}" ) ) ;
104
+ editor. insert_all (
105
+ Position :: after ( impl_. syntax ( ) ) ,
106
+ vec ! [
107
+ make:: tokens:: whitespace( & format!( "\n \n {indent}" ) ) . into( ) ,
108
+ impl_. syntax( ) . clone_for_update( ) . into( ) ,
109
+ ] ,
110
+ ) ;
111
+
112
+ if let Some ( cap) = ctx. config . snippet_cap {
113
+ edit. add_tabstop_before ( cap, impl_) ;
114
+ }
115
+
116
+ edit. add_file_edits ( ctx. vfs_file_id ( ) , editor) ;
104
117
} ,
105
118
)
106
119
}
0 commit comments