Skip to content

Commit 8d7cda3

Browse files
authored
Merge pull request #19362 from nemethf/fix-19322
Speed up resolving a "Generate delegate method" assist
2 parents dab1329 + f2ad0fc commit 8d7cda3

File tree

137 files changed

+562
-580
lines changed

Some content is hidden

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

137 files changed

+562
-580
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use syntax::{
33
ast::{self, edit_in_place::Indent, syntax_factory::SyntaxFactory},
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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
use hir::Semantics;
2-
use ide_db::{
3-
RootDatabase,
4-
assists::{AssistId, AssistKind},
5-
source_change::SourceChangeBuilder,
6-
};
2+
use ide_db::{RootDatabase, assists::AssistId, source_change::SourceChangeBuilder};
73
use syntax::{AstNode, ast};
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use syntax::{
44
ast::{self, AstNode, HasLoopBody},
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

Lines changed: 16 additions & 21 deletions
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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use syntax::{
55
};
66

77
use crate::{
8-
AssistId, AssistKind,
8+
AssistId,
99
assist_context::{AssistContext, Assists},
1010
utils::{
1111
DefaultMethods, IgnoreAssocItems, add_trait_assoc_items_to_impl, filter_assoc_items,
@@ -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

Lines changed: 2 additions & 2 deletions
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, AstNode, MatchArmList, MatchExpr, Pat, make};
1414

15-
use crate::{AssistContext, AssistId, AssistKind, Assists, utils};
15+
use crate::{AssistContext, AssistId, Assists, utils};
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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use hir::HirDisplay;
22
use syntax::{AstNode, SyntaxKind, SyntaxToken, TextRange, TextSize, ast, match_ast};
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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use syntax::{
77
};
88

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

@@ -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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use syntax::{
1717
syntax_editor::{Position, SyntaxEditor},
1818
};
1919

20-
use crate::{AssistContext, AssistId, AssistKind, Assists, utils::invert_boolean_expression};
20+
use crate::{AssistContext, AssistId, Assists, utils::invert_boolean_expression};
2121

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

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

0 commit comments

Comments
 (0)