1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
#[allow(unused)]
macro_rules! eprintln {
($($tt:tt)*) => { stdx::eprintln!($($tt)*) };
}
mod assist_config;
mod assist_context;
#[cfg(test)]
mod tests;
pub mod utils;
use hir::Semantics;
use ide_db::{base_db::FileRange, RootDatabase};
use syntax::TextRange;
pub(crate) use crate::assist_context::{AssistContext, Assists};
pub use assist_config::AssistConfig;
pub use ide_db::assists::{
Assist, AssistId, AssistKind, AssistResolveStrategy, GroupLabel, SingleResolve,
};
pub fn assists(
db: &RootDatabase,
config: &AssistConfig,
resolve: AssistResolveStrategy,
range: FileRange,
) -> Vec<Assist> {
let sema = Semantics::new(db);
let ctx = AssistContext::new(sema, config, range);
let mut acc = Assists::new(&ctx, resolve);
handlers::all().iter().for_each(|handler| {
handler(&mut acc, &ctx);
});
acc.finish()
}
mod handlers {
use crate::{AssistContext, Assists};
pub(crate) type Handler = fn(&mut Assists, &AssistContext) -> Option<()>;
mod add_explicit_type;
mod add_lifetime_to_type;
mod add_missing_impl_members;
mod add_turbo_fish;
mod apply_demorgan;
mod auto_import;
mod change_visibility;
mod convert_bool_then;
mod convert_comment_block;
mod convert_integer_literal;
mod convert_into_to_from;
mod convert_iter_for_each_to_for;
mod convert_tuple_struct_to_named_struct;
mod convert_to_guarded_return;
mod convert_while_to_loop;
mod destructure_tuple_binding;
mod expand_glob_import;
mod extract_function;
mod extract_module;
mod extract_struct_from_enum_variant;
mod extract_type_alias;
mod extract_variable;
mod add_missing_match_arms;
mod fix_visibility;
mod flip_binexpr;
mod flip_comma;
mod flip_trait_bound;
mod generate_constant;
mod generate_default_from_enum_variant;
mod generate_default_from_new;
mod generate_deref;
mod generate_derive;
mod generate_documentation_template;
mod generate_enum_is_method;
mod generate_enum_projection_method;
mod generate_from_impl_for_enum;
mod generate_function;
mod generate_getter;
mod generate_impl;
mod generate_is_empty_from_len;
mod generate_new;
mod generate_setter;
mod generate_delegate_methods;
mod add_return_type;
mod inline_call;
mod inline_local_variable;
mod introduce_named_lifetime;
mod invert_if;
mod merge_imports;
mod merge_match_arms;
mod move_bounds;
mod move_guard;
mod move_module_to_file;
mod move_to_mod_rs;
mod move_from_mod_rs;
mod number_representation;
mod promote_local_to_const;
mod pull_assignment_up;
mod qualify_path;
mod qualify_method_call;
mod raw_string;
mod remove_dbg;
mod remove_mut;
mod remove_unused_param;
mod reorder_fields;
mod reorder_impl;
mod replace_try_expr_with_match;
mod replace_derive_with_manual_impl;
mod replace_if_let_with_match;
mod introduce_named_generic;
mod replace_let_with_if_let;
mod replace_qualified_name_with_use;
mod replace_string_with_char;
mod replace_turbofish_with_explicit_type;
mod split_import;
mod sort_items;
mod toggle_ignore;
mod unmerge_use;
mod unwrap_block;
mod unwrap_result_return_type;
mod wrap_return_type_in_result;
pub(crate) fn all() -> &'static [Handler] {
&[
add_explicit_type::add_explicit_type,
add_missing_match_arms::add_missing_match_arms,
add_lifetime_to_type::add_lifetime_to_type,
add_return_type::add_return_type,
add_turbo_fish::add_turbo_fish,
apply_demorgan::apply_demorgan,
auto_import::auto_import,
change_visibility::change_visibility,
convert_bool_then::convert_bool_then_to_if,
convert_bool_then::convert_if_to_bool_then,
convert_comment_block::convert_comment_block,
convert_integer_literal::convert_integer_literal,
convert_into_to_from::convert_into_to_from,
convert_iter_for_each_to_for::convert_iter_for_each_to_for,
convert_iter_for_each_to_for::convert_for_loop_with_for_each,
convert_to_guarded_return::convert_to_guarded_return,
convert_tuple_struct_to_named_struct::convert_tuple_struct_to_named_struct,
convert_while_to_loop::convert_while_to_loop,
destructure_tuple_binding::destructure_tuple_binding,
expand_glob_import::expand_glob_import,
extract_struct_from_enum_variant::extract_struct_from_enum_variant,
extract_type_alias::extract_type_alias,
fix_visibility::fix_visibility,
flip_binexpr::flip_binexpr,
flip_comma::flip_comma,
flip_trait_bound::flip_trait_bound,
generate_constant::generate_constant,
generate_default_from_enum_variant::generate_default_from_enum_variant,
generate_default_from_new::generate_default_from_new,
generate_derive::generate_derive,
generate_documentation_template::generate_documentation_template,
generate_enum_is_method::generate_enum_is_method,
generate_enum_projection_method::generate_enum_as_method,
generate_enum_projection_method::generate_enum_try_into_method,
generate_from_impl_for_enum::generate_from_impl_for_enum,
generate_function::generate_function,
generate_impl::generate_impl,
generate_is_empty_from_len::generate_is_empty_from_len,
generate_new::generate_new,
inline_call::inline_call,
inline_call::inline_into_callers,
inline_local_variable::inline_local_variable,
introduce_named_generic::introduce_named_generic,
introduce_named_lifetime::introduce_named_lifetime,
invert_if::invert_if,
merge_imports::merge_imports,
merge_match_arms::merge_match_arms,
move_bounds::move_bounds_to_where_clause,
move_guard::move_arm_cond_to_match_guard,
move_guard::move_guard_to_arm_body,
move_module_to_file::move_module_to_file,
move_to_mod_rs::move_to_mod_rs,
move_from_mod_rs::move_from_mod_rs,
number_representation::reformat_number_literal,
pull_assignment_up::pull_assignment_up,
promote_local_to_const::promote_local_to_const,
qualify_path::qualify_path,
qualify_method_call::qualify_method_call,
raw_string::add_hash,
raw_string::make_usual_string,
raw_string::remove_hash,
remove_dbg::remove_dbg,
remove_mut::remove_mut,
remove_unused_param::remove_unused_param,
reorder_fields::reorder_fields,
reorder_impl::reorder_impl,
replace_try_expr_with_match::replace_try_expr_with_match,
replace_derive_with_manual_impl::replace_derive_with_manual_impl,
replace_if_let_with_match::replace_if_let_with_match,
replace_if_let_with_match::replace_match_with_if_let,
replace_let_with_if_let::replace_let_with_if_let,
replace_turbofish_with_explicit_type::replace_turbofish_with_explicit_type,
replace_qualified_name_with_use::replace_qualified_name_with_use,
sort_items::sort_items,
split_import::split_import,
toggle_ignore::toggle_ignore,
unmerge_use::unmerge_use,
unwrap_block::unwrap_block,
unwrap_result_return_type::unwrap_result_return_type,
wrap_return_type_in_result::wrap_return_type_in_result,
add_missing_impl_members::add_missing_impl_members,
add_missing_impl_members::add_missing_default_members,
replace_string_with_char::replace_string_with_char,
replace_string_with_char::replace_char_with_string,
raw_string::make_raw_string,
extract_variable::extract_variable,
extract_function::extract_function,
extract_module::extract_module,
generate_getter::generate_getter,
generate_getter::generate_getter_mut,
generate_setter::generate_setter,
generate_delegate_methods::generate_delegate_methods,
generate_deref::generate_deref,
]
}
}