Skip to content

Commit c86a7fe

Browse files
committed
Speed up resolving "Generate delegate method" assist (part 2)
Make it compile by adding a `None` subtype to rest of the AssistId instantiations.
1 parent f9c3602 commit c86a7fe

File tree

133 files changed

+513
-551
lines changed

Some content is hidden

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

133 files changed

+513
-551
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use syntax::{
33
AstNode,
44
};
55

6-
use crate::{AssistContext, AssistId, AssistKind, Assists};
6+
use crate::{AssistContext, AssistId, Assists};
77

88
// Assist: add_braces
99
//
@@ -32,7 +32,7 @@ pub(crate) fn add_braces(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<(
3232
let (expr_type, expr) = get_replacement_node(ctx)?;
3333

3434
acc.add(
35-
AssistId("add_braces", AssistKind::RefactorRewrite),
35+
AssistId::refactor_rewrite("add_braces"),
3636
match expr_type {
3737
ParentType::ClosureExpr => "Add braces to closure body",
3838
ParentType::MatchArmExpr => "Add braces to arm expression",

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

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
use hir::Semantics;
2-
use ide_db::{
3-
assists::{AssistId, AssistKind},
4-
source_change::SourceChangeBuilder,
5-
RootDatabase,
6-
};
2+
use ide_db::{assists::AssistId, source_change::SourceChangeBuilder, RootDatabase};
73
use syntax::{ast, AstNode};
84

95
use crate::{AssistContext, Assists};
@@ -53,7 +49,7 @@ pub(crate) fn add_explicit_enum_discriminant(
5349
}
5450

5551
acc.add(
56-
AssistId("add_explicit_enum_discriminant", AssistKind::RefactorRewrite),
52+
AssistId::refactor_rewrite("add_explicit_enum_discriminant"),
5753
"Add explicit enum discriminants",
5854
enum_node.syntax().text_range(),
5955
|builder| {

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use hir::HirDisplay;
22
use ide_db::syntax_helpers::node_ext::walk_ty;
33
use syntax::ast::{self, AstNode, LetStmt, Param};
44

5-
use crate::{AssistContext, AssistId, AssistKind, Assists};
5+
use crate::{AssistContext, AssistId, Assists};
66

77
// Assist: add_explicit_type
88
//
@@ -71,7 +71,7 @@ pub(crate) fn add_explicit_type(acc: &mut Assists, ctx: &AssistContext<'_>) -> O
7171

7272
let inferred_type = ty.display_source_code(ctx.db(), module.into(), false).ok()?;
7373
acc.add(
74-
AssistId("add_explicit_type", AssistKind::RefactorRewrite),
74+
AssistId::refactor_rewrite("add_explicit_type"),
7575
format!("Insert explicit type `{inferred_type}`"),
7676
pat_range,
7777
|builder| match ascribed_ty {

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use syntax::{
44
T,
55
};
66

7-
use crate::{AssistContext, AssistId, AssistKind, Assists};
7+
use crate::{AssistContext, AssistId, Assists};
88

99
// Assist: add_label_to_loop
1010
//
@@ -35,7 +35,7 @@ pub(crate) fn add_label_to_loop(acc: &mut Assists, ctx: &AssistContext<'_>) -> O
3535
}
3636

3737
acc.add(
38-
AssistId("add_label_to_loop", AssistKind::Generate),
38+
AssistId::generate("add_label_to_loop"),
3939
"Add Label",
4040
loop_expr.syntax().text_range(),
4141
|builder| {

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

+16-21
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use syntax::ast::{self, AstNode, HasGenericParams, HasName};
22

3-
use crate::{AssistContext, AssistId, AssistKind, Assists};
3+
use crate::{AssistContext, AssistId, Assists};
44

55
// Assist: add_lifetime_to_type
66
//
@@ -37,31 +37,26 @@ pub(crate) fn add_lifetime_to_type(acc: &mut Assists, ctx: &AssistContext<'_>) -
3737
let ref_types = fetch_borrowed_types(&node)?;
3838
let target = node.syntax().text_range();
3939

40-
acc.add(
41-
AssistId("add_lifetime_to_type", AssistKind::Generate),
42-
"Add lifetime",
43-
target,
44-
|builder| {
45-
match node.generic_param_list() {
46-
Some(gen_param) => {
47-
if let Some(left_angle) = gen_param.l_angle_token() {
48-
builder.insert(left_angle.text_range().end(), "'a, ");
49-
}
40+
acc.add(AssistId::generate("add_lifetime_to_type"), "Add lifetime", target, |builder| {
41+
match node.generic_param_list() {
42+
Some(gen_param) => {
43+
if let Some(left_angle) = gen_param.l_angle_token() {
44+
builder.insert(left_angle.text_range().end(), "'a, ");
5045
}
51-
None => {
52-
if let Some(name) = node.name() {
53-
builder.insert(name.syntax().text_range().end(), "<'a>");
54-
}
46+
}
47+
None => {
48+
if let Some(name) = node.name() {
49+
builder.insert(name.syntax().text_range().end(), "<'a>");
5550
}
5651
}
52+
}
5753

58-
for ref_type in ref_types {
59-
if let Some(amp_token) = ref_type.amp_token() {
60-
builder.insert(amp_token.text_range().end(), "'a ");
61-
}
54+
for ref_type in ref_types {
55+
if let Some(amp_token) = ref_type.amp_token() {
56+
builder.insert(amp_token.text_range().end(), "'a ");
6257
}
63-
},
64-
)
58+
}
59+
})
6560
}
6661

6762
fn fetch_borrowed_types(node: &ast::Adt) -> Option<Vec<ast::RefType>> {

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::{
1010
add_trait_assoc_items_to_impl, filter_assoc_items, gen_trait_fn_body, DefaultMethods,
1111
IgnoreAssocItems,
1212
},
13-
AssistId, AssistKind,
13+
AssistId,
1414
};
1515

1616
// Assist: add_impl_missing_members
@@ -146,7 +146,7 @@ fn add_missing_impl_members_inner(
146146
}
147147

148148
let target = impl_def.syntax().text_range();
149-
acc.add(AssistId(assist_id, AssistKind::QuickFix), label, target, |edit| {
149+
acc.add(AssistId::quick_fix(assist_id), label, target, |edit| {
150150
let new_impl_def = edit.make_mut(impl_def.clone());
151151
let first_new_item = add_trait_assoc_items_to_impl(
152152
&ctx.sema,

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use syntax::ast::edit_in_place::Indent;
1212
use syntax::ast::syntax_factory::SyntaxFactory;
1313
use syntax::ast::{self, make, AstNode, MatchArmList, MatchExpr, Pat};
1414

15-
use crate::{utils, AssistContext, AssistId, AssistKind, Assists};
15+
use crate::{utils, AssistContext, AssistId, Assists};
1616

1717
// Assist: add_missing_match_arms
1818
//
@@ -205,7 +205,7 @@ pub(crate) fn add_missing_match_arms(acc: &mut Assists, ctx: &AssistContext<'_>)
205205
}
206206

207207
acc.add(
208-
AssistId("add_missing_match_arms", AssistKind::QuickFix),
208+
AssistId::quick_fix("add_missing_match_arms"),
209209
"Fill match arms",
210210
ctx.sema.original_range(match_expr.syntax()).range,
211211
|builder| {

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use hir::HirDisplay;
22
use syntax::{ast, match_ast, AstNode, SyntaxKind, SyntaxToken, TextRange, TextSize};
33

4-
use crate::{AssistContext, AssistId, AssistKind, Assists};
4+
use crate::{AssistContext, AssistId, Assists};
55

66
// Assist: add_return_type
77
//
@@ -25,7 +25,7 @@ pub(crate) fn add_return_type(acc: &mut Assists, ctx: &AssistContext<'_>) -> Opt
2525
let ty = ty.display_source_code(ctx.db(), module.into(), true).ok()?;
2626

2727
acc.add(
28-
AssistId("add_return_type", AssistKind::RefactorRewrite),
28+
AssistId::refactor_rewrite("add_return_type"),
2929
match fn_type {
3030
FnType::Function => "Add this function's return type",
3131
FnType::Closure { .. } => "Add this closure's return type",

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use syntax::{
88

99
use crate::{
1010
assist_context::{AssistContext, Assists},
11-
AssistId, AssistKind,
11+
AssistId,
1212
};
1313

1414
// Assist: add_turbo_fish
@@ -89,7 +89,7 @@ pub(crate) fn add_turbo_fish(acc: &mut Assists, ctx: &AssistContext<'_>) -> Opti
8989
let_stmt.pat()?;
9090

9191
acc.add(
92-
AssistId("add_type_ascription", AssistKind::RefactorRewrite),
92+
AssistId::refactor_rewrite("add_type_ascription"),
9393
"Add `: _` before assignment operator",
9494
ident.text_range(),
9595
|builder| {
@@ -135,7 +135,7 @@ pub(crate) fn add_turbo_fish(acc: &mut Assists, ctx: &AssistContext<'_>) -> Opti
135135
.count();
136136

137137
acc.add(
138-
AssistId("add_turbo_fish", AssistKind::RefactorRewrite),
138+
AssistId::refactor_rewrite("add_turbo_fish"),
139139
"Add `::<>`",
140140
ident.text_range(),
141141
|builder| {

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use syntax::{
1818
SyntaxKind, T,
1919
};
2020

21-
use crate::{utils::invert_boolean_expression, AssistContext, AssistId, AssistKind, Assists};
21+
use crate::{utils::invert_boolean_expression, AssistContext, AssistId, Assists};
2222

2323
// Assist: apply_demorgan
2424
//
@@ -108,7 +108,7 @@ pub(crate) fn apply_demorgan(acc: &mut Assists, ctx: &AssistContext<'_>) -> Opti
108108

109109
acc.add_group(
110110
&GroupLabel("Apply De Morgan's law".to_owned()),
111-
AssistId("apply_demorgan", AssistKind::RefactorRewrite),
111+
AssistId::refactor_rewrite("apply_demorgan"),
112112
"Apply De Morgan's law",
113113
op_range,
114114
|builder| {
@@ -191,7 +191,7 @@ pub(crate) fn apply_demorgan_iterator(acc: &mut Assists, ctx: &AssistContext<'_>
191191
let label = format!("Apply De Morgan's law to `Iterator::{}`", name.text().as_str());
192192
acc.add_group(
193193
&GroupLabel("Apply De Morgan's law".to_owned()),
194-
AssistId("apply_demorgan_iterator", AssistKind::RefactorRewrite),
194+
AssistId::refactor_rewrite("apply_demorgan_iterator"),
195195
label,
196196
op_range,
197197
|builder| {

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use ide_db::{
1010
};
1111
use syntax::{ast, AstNode, Edition, NodeOrToken, SyntaxElement};
1212

13-
use crate::{AssistContext, AssistId, AssistKind, Assists, GroupLabel};
13+
use crate::{AssistContext, AssistId, Assists, GroupLabel};
1414

1515
// Feature: Auto Import
1616
//
@@ -127,7 +127,7 @@ pub(crate) fn auto_import(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<
127127
let import_path = import.import_path;
128128

129129
let (assist_id, import_name) =
130-
(AssistId("auto_import", AssistKind::QuickFix), import_path.display(ctx.db(), edition));
130+
(AssistId::quick_fix("auto_import"), import_path.display(ctx.db(), edition));
131131
acc.add_group(
132132
&group_label,
133133
assist_id,

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

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
use crate::assist_context::{AssistContext, Assists};
2-
use ide_db::{
3-
assists::{AssistId, AssistKind},
4-
defs::Definition,
5-
LineIndexDatabase,
6-
};
2+
use ide_db::{assists::AssistId, defs::Definition, LineIndexDatabase};
73
use syntax::{
84
ast::{self, edit_in_place::Indent},
95
AstNode,
@@ -42,7 +38,7 @@ pub(crate) fn bind_unused_param(acc: &mut Assists, ctx: &AssistContext<'_>) -> O
4238
let r_curly_range = stmt_list.r_curly_token()?.text_range();
4339

4440
acc.add(
45-
AssistId("bind_unused_param", AssistKind::QuickFix),
41+
AssistId::quick_fix("bind_unused_param"),
4642
format!("Bind as `let _ = {ident_pat};`"),
4743
param.syntax().text_range(),
4844
|builder| {

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use syntax::{
88
SyntaxNode, T,
99
};
1010

11-
use crate::{utils::vis_offset, AssistContext, AssistId, AssistKind, Assists};
11+
use crate::{utils::vis_offset, AssistContext, AssistId, Assists};
1212

1313
// Assist: change_visibility
1414
//
@@ -76,7 +76,7 @@ fn add_vis(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
7676
};
7777

7878
acc.add(
79-
AssistId("change_visibility", AssistKind::RefactorRewrite),
79+
AssistId::refactor_rewrite("change_visibility"),
8080
"Change visibility to pub(crate)",
8181
target,
8282
|edit| {
@@ -112,7 +112,7 @@ fn change_vis(acc: &mut Assists, vis: ast::Visibility) -> Option<()> {
112112
if vis.syntax().text() == "pub" {
113113
let target = vis.syntax().text_range();
114114
return acc.add(
115-
AssistId("change_visibility", AssistKind::RefactorRewrite),
115+
AssistId::refactor_rewrite("change_visibility"),
116116
"Change Visibility to pub(crate)",
117117
target,
118118
|edit| {
@@ -123,7 +123,7 @@ fn change_vis(acc: &mut Assists, vis: ast::Visibility) -> Option<()> {
123123
if vis.syntax().text() == "pub(crate)" {
124124
let target = vis.syntax().text_range();
125125
return acc.add(
126-
AssistId("change_visibility", AssistKind::RefactorRewrite),
126+
AssistId::refactor_rewrite("change_visibility"),
127127
"Change visibility to pub",
128128
target,
129129
|edit| {

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use syntax::{
1515

1616
use crate::{
1717
utils::{invert_boolean_expression, unwrap_trivial_block},
18-
AssistContext, AssistId, AssistKind, Assists,
18+
AssistContext, AssistId, Assists,
1919
};
2020

2121
// Assist: convert_if_to_bool_then
@@ -73,7 +73,7 @@ pub(crate) fn convert_if_to_bool_then(acc: &mut Assists, ctx: &AssistContext<'_>
7373

7474
let target = expr.syntax().text_range();
7575
acc.add(
76-
AssistId("convert_if_to_bool_then", AssistKind::RefactorRewrite),
76+
AssistId::refactor_rewrite("convert_if_to_bool_then"),
7777
"Convert `if` expression to `bool::then` call",
7878
target,
7979
|builder| {
@@ -181,7 +181,7 @@ pub(crate) fn convert_bool_then_to_if(acc: &mut Assists, ctx: &AssistContext<'_>
181181

182182
let target = mcall.syntax().text_range();
183183
acc.add(
184-
AssistId("convert_bool_then_to_if", AssistKind::RefactorRewrite),
184+
AssistId::refactor_rewrite("convert_bool_then_to_if"),
185185
"Convert `bool::then` call to `if`",
186186
target,
187187
|builder| {

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use either::Either;
22
use hir::ModuleDef;
33
use ide_db::text_edit::TextRange;
44
use ide_db::{
5-
assists::{AssistId, AssistKind},
5+
assists::AssistId,
66
defs::Definition,
77
helpers::mod_path_to_ast,
88
imports::insert_use::{insert_use, ImportScope},
@@ -62,7 +62,7 @@ pub(crate) fn convert_bool_to_enum(acc: &mut Assists, ctx: &AssistContext<'_>) -
6262

6363
let target = name.syntax().text_range();
6464
acc.add(
65-
AssistId("convert_bool_to_enum", AssistKind::RefactorRewrite),
65+
AssistId::refactor_rewrite("convert_bool_to_enum"),
6666
"Convert boolean to enum",
6767
target,
6868
|edit| {

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

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
use either::Either;
22
use hir::{CaptureKind, ClosureCapture, FileRangeWrapper, HirDisplay};
33
use ide_db::{
4-
assists::{AssistId, AssistKind},
5-
base_db::SourceDatabase,
6-
defs::Definition,
7-
search::FileReferenceNode,
8-
source_change::SourceChangeBuilder,
9-
FxHashSet,
4+
assists::AssistId, base_db::SourceDatabase, defs::Definition, search::FileReferenceNode,
5+
source_change::SourceChangeBuilder, FxHashSet,
106
};
117
use stdx::format_to;
128
use syntax::{
@@ -146,7 +142,7 @@ pub(crate) fn convert_closure_to_fn(acc: &mut Assists, ctx: &AssistContext<'_>)
146142
};
147143

148144
acc.add(
149-
AssistId("convert_closure_to_fn", AssistKind::RefactorRewrite),
145+
AssistId::refactor_rewrite("convert_closure_to_fn"),
150146
"Convert closure to fn",
151147
closure.param_list()?.syntax().text_range(),
152148
|builder| {

0 commit comments

Comments
 (0)