Skip to content

Commit 903b5c9

Browse files
snippet edit support no longer experimental
1 parent c8846c4 commit 903b5c9

63 files changed

Lines changed: 343 additions & 425 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 24 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/ide-assists/src/assist_config.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
//! Settings for tweaking assists.
2-
//!
3-
//! The fun thing here is `SnippetCap` -- this type can only be created in this
4-
//! module, and we use to statically check that we only produce snippet
5-
//! assists if we are allowed to.
62
73
use hir::FindPathConfig;
84
use ide_db::{
9-
SnippetCap,
105
assists::ExprFillDefaultMode,
116
imports::{import_assets::ImportPathConfig, insert_use::InsertUseConfig},
127
rename::RenameConfig,
@@ -16,7 +11,7 @@ use crate::AssistKind;
1611

1712
#[derive(Clone, Debug, PartialEq, Eq)]
1813
pub struct AssistConfig {
19-
pub snippet_cap: Option<SnippetCap>,
14+
pub snippet_edit_support: bool,
2015
pub allowed: Option<Vec<AssistKind>>,
2116
pub insert_use: InsertUseConfig,
2217
pub prefer_no_std: bool,

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ pub(crate) fn add_label_to_loop(acc: &mut Assists, ctx: &AssistContext<'_>) -> O
5353
];
5454
editor.insert_all(Position::before(&loop_kw), elements);
5555

56-
if let Some(cap) = ctx.config.snippet_cap {
57-
editor.add_annotation(label.syntax(), builder.make_placeholder_snippet(cap));
56+
if ctx.config.snippet_edit_support {
57+
editor.add_annotation(label.syntax(), builder.make_placeholder_snippet());
5858
}
5959

6060
let loop_body = loop_expr.loop_body().and_then(|it| it.stmt_list());
@@ -94,8 +94,8 @@ fn insert_label_after_token(
9494
let elements = vec![make.whitespace(" ").into(), label.syntax().clone().into()];
9595
editor.insert_all(Position::after(token), elements);
9696

97-
if let Some(cap) = ctx.config.snippet_cap {
98-
editor.add_annotation(label.syntax(), builder.make_placeholder_snippet(cap));
97+
if ctx.config.snippet_edit_support {
98+
editor.add_annotation(label.syntax(), builder.make_placeholder_snippet());
9999
}
100100
}
101101

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ fn add_missing_impl_members_inner(
200200
first_new_item = assoc_item_list.assoc_items().next();
201201
}
202202

203-
if let Some(cap) = ctx.config.snippet_cap {
203+
if ctx.config.snippet_edit_support {
204204
let mut placeholder = None;
205205
if let DefaultMethods::No = mode
206206
&& let Some(ast::AssocItem::Fn(func)) = &first_new_item
@@ -211,10 +211,10 @@ fn add_missing_impl_members_inner(
211211
}
212212

213213
if let Some(macro_call) = placeholder {
214-
let placeholder = edit.make_placeholder_snippet(cap);
214+
let placeholder = edit.make_placeholder_snippet();
215215
editor.add_annotation(macro_call.syntax(), placeholder);
216216
} else if let Some(first_new_item) = first_new_item {
217-
let tabstop = edit.make_tabstop_before(cap);
217+
let tabstop = edit.make_tabstop_before();
218218
editor.add_annotation(first_new_item.syntax(), tabstop);
219219
};
220220
};

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,22 +278,22 @@ pub(crate) fn add_missing_match_arms(acc: &mut Assists, ctx: &AssistContext<'_>)
278278
arms_edit.add_comma_after_last_arm(ctx, &make, &editor);
279279
arms_edit.append_arms(&missing_arms, &make, &editor);
280280

281-
if let Some(cap) = ctx.config.snippet_cap {
281+
if ctx.config.snippet_edit_support {
282282
if let Some(it) = missing_arms
283283
.first()
284284
.and_then(|arm| arm.syntax().descendants().find_map(ast::WildcardPat::cast))
285285
{
286-
editor.add_annotation(it.syntax(), builder.make_placeholder_snippet(cap));
286+
editor.add_annotation(it.syntax(), builder.make_placeholder_snippet());
287287
}
288288

289289
for arm in &missing_arms {
290290
if let Some(expr) = arm.expr() {
291-
editor.add_annotation(expr.syntax(), builder.make_placeholder_snippet(cap));
291+
editor.add_annotation(expr.syntax(), builder.make_placeholder_snippet());
292292
}
293293
}
294294

295295
if let Some(arm) = missing_arms.last() {
296-
editor.add_annotation(arm.syntax(), builder.make_tabstop_after(cap));
296+
editor.add_annotation(arm.syntax(), builder.make_tabstop_after());
297297
}
298298
}
299299

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@ pub(crate) fn add_turbo_fish(acc: &mut Assists, ctx: &AssistContext<'_>) -> Opti
112112
placeholder_ty.syntax().clone().into(),
113113
];
114114
editor.insert_all(Position::after(pat.syntax()), elements);
115-
if let Some(cap) = ctx.config.snippet_cap {
115+
if ctx.config.snippet_edit_support {
116116
editor.add_annotation(
117117
placeholder_ty.syntax(),
118-
builder.make_placeholder_snippet(cap),
118+
builder.make_placeholder_snippet(),
119119
);
120120
}
121121
}
@@ -173,9 +173,9 @@ pub(crate) fn add_turbo_fish(acc: &mut Assists, ctx: &AssistContext<'_>) -> Opti
173173
}
174174
};
175175

176-
if let Some(cap) = ctx.config.snippet_cap {
176+
if ctx.config.snippet_edit_support {
177177
for arg in fish_head.generic_args() {
178-
editor.add_annotation(arg.syntax(), builder.make_placeholder_snippet(cap));
178+
editor.add_annotation(arg.syntax(), builder.make_placeholder_snippet());
179179
}
180180
}
181181
builder.add_file_edits(ctx.vfs_file_id(), editor);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@ pub(crate) fn convert_from_to_tryfrom(acc: &mut Assists, ctx: &AssistContext<'_>
9494
make.ty_alias(None, "Error", None, None, None, Some((make.ty("()"), None)));
9595
let error_type = ast::AssocItem::TypeAlias(error_type_alias);
9696

97-
if let Some(cap) = ctx.config.snippet_cap
97+
if ctx.config.snippet_edit_support
9898
&& let ast::AssocItem::TypeAlias(type_alias) = &error_type
9999
&& let Some(ty) = type_alias.ty()
100100
{
101-
let placeholder = builder.make_placeholder_snippet(cap);
101+
let placeholder = builder.make_placeholder_snippet();
102102
editor.add_annotation(ty.syntax(), placeholder);
103103
}
104104

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,10 @@ fn edit_tuple_assignment(
192192
.and_then(ast::RecordPatField::for_field_name)
193193
.is_some_and(|field| field.colon_token().is_none());
194194

195-
if let Some(cap) = ctx.config.snippet_cap {
195+
if ctx.config.snippet_edit_support {
196196
// place cursor on first tuple name
197197
if let Some(ast::Pat::IdentPat(first_pat)) = tuple_pat.fields().next() {
198-
let annotation = edit.make_tabstop_before(cap);
198+
let annotation = edit.make_tabstop_before();
199199
editor.add_annotation(
200200
first_pat.name().expect("first ident pattern should have a name").syntax(),
201201
annotation,

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ pub(crate) fn extract_expressions_from_format_string(
134134
let new_tt = make.token_tree(tt_delimiter, new_tt_bits);
135135
editor.replace(tt.syntax(), new_tt.syntax());
136136

137-
if let Some(cap) = ctx.config.snippet_cap {
137+
if ctx.config.snippet_edit_support {
138138
// Add placeholder snippets over placeholder args
139139
for pos in placeholder_indexes {
140140
// Skip the opening delimiter
@@ -145,7 +145,7 @@ pub(crate) fn extract_expressions_from_format_string(
145145
};
146146

147147
if stdx::always!(placeholder.kind() == T![_]) {
148-
let annotation = edit.make_placeholder_snippet(cap);
148+
let annotation = edit.make_placeholder_snippet();
149149
editor.add_annotation(placeholder, annotation);
150150
}
151151
}
@@ -154,7 +154,7 @@ pub(crate) fn extract_expressions_from_format_string(
154154
if let Some(NodeOrToken::Token(literal)) =
155155
new_tt.token_trees_and_tokens().nth(1 + format_string_index)
156156
{
157-
let annotation = edit.make_tabstop_after(cap);
157+
let annotation = edit.make_tabstop_after();
158158
editor.add_annotation(literal, annotation);
159159
}
160160
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,10 @@ pub(crate) fn extract_function(acc: &mut Assists, ctx: &AssistContext<'_>) -> Op
177177

178178
let fn_def = format_function(ctx, module, &fun, old_indent).clone_for_update();
179179

180-
if let Some(cap) = ctx.config.snippet_cap
180+
if ctx.config.snippet_edit_support
181181
&& let Some(name) = fn_def.name()
182182
{
183-
builder.add_tabstop_before(cap, name);
183+
builder.add_tabstop_before(name);
184184
}
185185

186186
// FIXME: wrap non-adt types

0 commit comments

Comments
 (0)