Skip to content

Commit c1edbfb

Browse files
committed
better assist label
1 parent 50923ad commit c1edbfb

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

crates/ide_assists/src/handlers/generate_function.rs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ fn gen_fn(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
8888
let (target, file, insert_offset) = get_fn_target(ctx, &target_module, call.clone())?;
8989
let function_builder = FunctionBuilder::from_call(ctx, &call, &path, target_module, target)?;
9090
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)
9293
}
9394

9495
fn gen_method(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
@@ -114,6 +115,7 @@ fn gen_method(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
114115
FunctionBuilder::from_method_call(ctx, &call, &fn_name, target_module, target)?;
115116
let text_range = call.syntax().text_range();
116117
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());
117119
add_func_to_accumulator(
118120
acc,
119121
ctx,
@@ -122,6 +124,7 @@ fn gen_method(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
122124
insert_offset,
123125
range.file_id,
124126
adt_name,
127+
label,
125128
)
126129
}
127130

@@ -133,24 +136,20 @@ fn add_func_to_accumulator(
133136
insert_offset: TextSize,
134137
file: FileId,
135138
adt_name: Option<hir::Name>,
139+
label: String,
136140
) -> 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!("\nimpl {} {{\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!("\nimpl {} {{\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+
})
154153
}
155154

156155
fn current_module(current_node: &SyntaxNode, ctx: &AssistContext) -> Option<Module> {

0 commit comments

Comments
 (0)