@@ -88,7 +88,8 @@ fn gen_fn(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
88
88
let ( target, file, insert_offset) = get_fn_target ( ctx, & target_module, call. clone ( ) ) ?;
89
89
let function_builder = FunctionBuilder :: from_call ( ctx, & call, & path, target_module, target) ?;
90
90
let target = call. syntax ( ) . text_range ( ) ;
91
- add_func_to_accumulator ( acc, ctx, target, function_builder, insert_offset, file, None )
91
+ let label = format ! ( "Generate {} function" , function_builder. fn_name. clone( ) ) ;
92
+ add_func_to_accumulator ( acc, ctx, target, function_builder, insert_offset, file, None , label)
92
93
}
93
94
94
95
fn gen_method ( acc : & mut Assists , ctx : & AssistContext ) -> Option < ( ) > {
@@ -114,6 +115,7 @@ fn gen_method(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
114
115
FunctionBuilder :: from_method_call ( ctx, & call, & fn_name, target_module, target) ?;
115
116
let text_range = call. syntax ( ) . text_range ( ) ;
116
117
let adt_name = if impl_. is_none ( ) { Some ( adt. name ( ctx. sema . db ) ) } else { None } ;
118
+ let label = format ! ( "Generate {} method" , function_builder. fn_name. clone( ) ) ;
117
119
add_func_to_accumulator (
118
120
acc,
119
121
ctx,
@@ -122,6 +124,7 @@ fn gen_method(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
122
124
insert_offset,
123
125
range. file_id ,
124
126
adt_name,
127
+ label,
125
128
)
126
129
}
127
130
@@ -133,24 +136,20 @@ fn add_func_to_accumulator(
133
136
insert_offset : TextSize ,
134
137
file : FileId ,
135
138
adt_name : Option < hir:: Name > ,
139
+ label : String ,
136
140
) -> Option < ( ) > {
137
- acc. add (
138
- AssistId ( "generate_function" , AssistKind :: Generate ) ,
139
- format ! ( "Generate `{}` method" , function_builder. fn_name) ,
140
- text_range,
141
- |builder| {
142
- let function_template = function_builder. render ( ) ;
143
- let mut func = function_template. to_string ( ctx. config . snippet_cap ) ;
144
- if let Some ( name) = adt_name {
145
- func = format ! ( "\n impl {} {{\n {}\n }}" , name, func) ;
146
- }
147
- builder. edit_file ( file) ;
148
- match ctx. config . snippet_cap {
149
- Some ( cap) => builder. insert_snippet ( cap, insert_offset, func) ,
150
- None => builder. insert ( insert_offset, func) ,
151
- }
152
- } ,
153
- )
141
+ acc. add ( AssistId ( "generate_function" , AssistKind :: Generate ) , label, text_range, |builder| {
142
+ let function_template = function_builder. render ( ) ;
143
+ let mut func = function_template. to_string ( ctx. config . snippet_cap ) ;
144
+ if let Some ( name) = adt_name {
145
+ func = format ! ( "\n impl {} {{\n {}\n }}" , name, func) ;
146
+ }
147
+ builder. edit_file ( file) ;
148
+ match ctx. config . snippet_cap {
149
+ Some ( cap) => builder. insert_snippet ( cap, insert_offset, func) ,
150
+ None => builder. insert ( insert_offset, func) ,
151
+ }
152
+ } )
154
153
}
155
154
156
155
fn current_module ( current_node : & SyntaxNode , ctx : & AssistContext ) -> Option < Module > {
0 commit comments