Skip to content

Commit aafa13f

Browse files
Unify snippet numbers
1 parent d1e3c34 commit aafa13f

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

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

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,22 @@ fn add_and_declare_lifetimes(
120120
editor.insert_all(Position::after(name.syntax()), final_elements);
121121
}
122122

123+
let snippet = ctx.config.snippet_cap.map(|cap| builder.make_placeholder_snippet(cap));
124+
123125
if let Some(lifetime) = new_lifetime_to_annotate
124-
&& let Some(cap) = ctx.config.snippet_cap
126+
&& let Some(snippet) = snippet
125127
{
126-
editor.add_annotation(lifetime.syntax(), builder.make_placeholder_snippet(cap));
128+
editor.add_annotation(lifetime.syntax(), snippet);
127129
}
128130

129131
if has_refs_without_lifetime {
130-
add_lifetime_to_refs(refs_without_lifetime, "'l", ctx, &mut editor, builder, &make);
132+
add_lifetime_to_refs(
133+
refs_without_lifetime,
134+
&new_lifetime_name,
135+
&mut editor,
136+
&make,
137+
snippet,
138+
);
131139
}
132140

133141
editor.add_mappings(make.finish_with_mappings());
@@ -183,19 +191,18 @@ fn find_all_ref_types_from_field_list(field_list: &ast::FieldList) -> Option<Vec
183191
fn add_lifetime_to_refs(
184192
refs_without_lifetime: Vec<ast::RefType>,
185193
lifetime_text: &str,
186-
ctx: &AssistContext<'_>,
187194
editor: &mut SyntaxEditor,
188-
builder: &mut SourceChangeBuilder,
189195
make: &SyntaxFactory,
196+
snippet: Option<SyntaxAnnotation>,
190197
) {
191198
for r#ref in refs_without_lifetime {
192199
let Some(amp_token) = r#ref.amp_token() else { continue };
193200
let lifetime = make.lifetime(lifetime_text);
194201
let node_or_token = &NodeOrToken::Token(amp_token);
195202
let elements = vec![lifetime.syntax().clone().into(), tokens::single_space().into()];
196203
editor.insert_all(Position::after(node_or_token), elements);
197-
if let Some(cap) = ctx.config.snippet_cap {
198-
editor.add_annotation(lifetime.syntax(), builder.make_placeholder_snippet(cap));
204+
if let Some(snippet) = snippet {
205+
editor.add_annotation(lifetime.syntax(), snippet);
199206
};
200207
}
201208
}

0 commit comments

Comments
 (0)