diff options
Diffstat (limited to 'crates/ide_assists/src/handlers')
8 files changed, 25 insertions, 10 deletions
diff --git a/crates/ide_assists/src/handlers/auto_import.rs b/crates/ide_assists/src/handlers/auto_import.rs index 7019039b9..5ccd7f7a2 100644 --- a/crates/ide_assists/src/handlers/auto_import.rs +++ b/crates/ide_assists/src/handlers/auto_import.rs | |||
@@ -61,6 +61,8 @@ use crate::{AssistContext, AssistId, AssistKind, Assists, GroupLabel}; | |||
61 | // - `plain`: This setting does not impose any restrictions in imports. | 61 | // - `plain`: This setting does not impose any restrictions in imports. |
62 | // | 62 | // |
63 | // In `VS Code` the configuration for this is `rust-analyzer.assist.importPrefix`. | 63 | // In `VS Code` the configuration for this is `rust-analyzer.assist.importPrefix`. |
64 | // | ||
65 | // image::https://user-images.githubusercontent.com/48062697/113020673-b85be580-917a-11eb-9022-59585f35d4f8.gif[] | ||
64 | 66 | ||
65 | // Assist: auto_import | 67 | // Assist: auto_import |
66 | // | 68 | // |
diff --git a/crates/ide_assists/src/handlers/extract_struct_from_enum_variant.rs b/crates/ide_assists/src/handlers/extract_struct_from_enum_variant.rs index 596c536a7..a8d6355bd 100644 --- a/crates/ide_assists/src/handlers/extract_struct_from_enum_variant.rs +++ b/crates/ide_assists/src/handlers/extract_struct_from_enum_variant.rs | |||
@@ -195,7 +195,7 @@ fn extract_struct_def( | |||
195 | 195 | ||
196 | fn update_variant(rewriter: &mut SyntaxRewriter, variant: &ast::Variant) -> Option<()> { | 196 | fn update_variant(rewriter: &mut SyntaxRewriter, variant: &ast::Variant) -> Option<()> { |
197 | let name = variant.name()?; | 197 | let name = variant.name()?; |
198 | let tuple_field = make::tuple_field(None, make::ty(name.text())); | 198 | let tuple_field = make::tuple_field(None, make::ty(&name.text())); |
199 | let replacement = make::variant( | 199 | let replacement = make::variant( |
200 | name, | 200 | name, |
201 | Some(ast::FieldList::TupleFieldList(make::tuple_field_list(iter::once(tuple_field)))), | 201 | Some(ast::FieldList::TupleFieldList(make::tuple_field_list(iter::once(tuple_field)))), |
diff --git a/crates/ide_assists/src/handlers/generate_default_from_new.rs b/crates/ide_assists/src/handlers/generate_default_from_new.rs index 81c54ba3e..dc14552d6 100644 --- a/crates/ide_assists/src/handlers/generate_default_from_new.rs +++ b/crates/ide_assists/src/handlers/generate_default_from_new.rs | |||
@@ -92,7 +92,7 @@ fn is_default_implemented(ctx: &AssistContext, impl_: &Impl) -> bool { | |||
92 | None => return false, | 92 | None => return false, |
93 | }; | 93 | }; |
94 | 94 | ||
95 | let ty = impl_def.target_ty(db); | 95 | let ty = impl_def.self_ty(db); |
96 | let krate = impl_def.module(db).krate(); | 96 | let krate = impl_def.module(db).krate(); |
97 | let default = FamousDefs(&ctx.sema, Some(krate)).core_default_Default(); | 97 | let default = FamousDefs(&ctx.sema, Some(krate)).core_default_Default(); |
98 | let default_trait = match default { | 98 | let default_trait = match default { |
diff --git a/crates/ide_assists/src/handlers/generate_enum_is_method.rs b/crates/ide_assists/src/handlers/generate_enum_is_method.rs index 7e181a480..a9f71a703 100644 --- a/crates/ide_assists/src/handlers/generate_enum_is_method.rs +++ b/crates/ide_assists/src/handlers/generate_enum_is_method.rs | |||
@@ -44,7 +44,7 @@ pub(crate) fn generate_enum_is_method(acc: &mut Assists, ctx: &AssistContext) -> | |||
44 | }; | 44 | }; |
45 | 45 | ||
46 | let enum_lowercase_name = to_lower_snake_case(&parent_enum.name()?.to_string()); | 46 | let enum_lowercase_name = to_lower_snake_case(&parent_enum.name()?.to_string()); |
47 | let fn_name = format!("is_{}", &to_lower_snake_case(variant_name.text())); | 47 | let fn_name = format!("is_{}", &to_lower_snake_case(&variant_name.text())); |
48 | 48 | ||
49 | // Return early if we've found an existing new fn | 49 | // Return early if we've found an existing new fn |
50 | let impl_def = find_struct_impl(&ctx, &parent_enum, &fn_name)?; | 50 | let impl_def = find_struct_impl(&ctx, &parent_enum, &fn_name)?; |
diff --git a/crates/ide_assists/src/handlers/generate_enum_projection_method.rs b/crates/ide_assists/src/handlers/generate_enum_projection_method.rs index 871bcab50..e2f572ba3 100644 --- a/crates/ide_assists/src/handlers/generate_enum_projection_method.rs +++ b/crates/ide_assists/src/handlers/generate_enum_projection_method.rs | |||
@@ -132,7 +132,8 @@ fn generate_enum_projection_method( | |||
132 | ast::StructKind::Unit => return None, | 132 | ast::StructKind::Unit => return None, |
133 | }; | 133 | }; |
134 | 134 | ||
135 | let fn_name = format!("{}_{}", props.fn_name_prefix, &to_lower_snake_case(variant_name.text())); | 135 | let fn_name = |
136 | format!("{}_{}", props.fn_name_prefix, &to_lower_snake_case(&variant_name.text())); | ||
136 | 137 | ||
137 | // Return early if we've found an existing new fn | 138 | // Return early if we've found an existing new fn |
138 | let impl_def = find_struct_impl(&ctx, &parent_enum, &fn_name)?; | 139 | let impl_def = find_struct_impl(&ctx, &parent_enum, &fn_name)?; |
diff --git a/crates/ide_assists/src/handlers/generate_impl.rs b/crates/ide_assists/src/handlers/generate_impl.rs index a8e3c4fc2..fd2e250bc 100644 --- a/crates/ide_assists/src/handlers/generate_impl.rs +++ b/crates/ide_assists/src/handlers/generate_impl.rs | |||
@@ -72,6 +72,17 @@ mod tests { | |||
72 | check_assist( | 72 | check_assist( |
73 | generate_impl, | 73 | generate_impl, |
74 | r#" | 74 | r#" |
75 | struct MyOwnArray<T, const S: usize> {}$0"#, | ||
76 | r#" | ||
77 | struct MyOwnArray<T, const S: usize> {} | ||
78 | |||
79 | impl<T, const S: usize> MyOwnArray<T, S> { | ||
80 | $0 | ||
81 | }"#, | ||
82 | ); | ||
83 | check_assist( | ||
84 | generate_impl, | ||
85 | r#" | ||
75 | #[cfg(feature = "foo")] | 86 | #[cfg(feature = "foo")] |
76 | struct Foo<'a, T: Foo<'a>> {$0}"#, | 87 | struct Foo<'a, T: Foo<'a>> {$0}"#, |
77 | r#" | 88 | r#" |
@@ -114,11 +125,11 @@ mod tests { | |||
114 | check_assist( | 125 | check_assist( |
115 | generate_impl, | 126 | generate_impl, |
116 | r#" | 127 | r#" |
117 | struct Defaulted<'a, 'b: 'a, T: Debug + Clone + 'a + 'b = String> {}$0"#, | 128 | struct Defaulted<'a, 'b: 'a, T: Debug + Clone + 'a + 'b = String, const S: usize> {}$0"#, |
118 | r#" | 129 | r#" |
119 | struct Defaulted<'a, 'b: 'a, T: Debug + Clone + 'a + 'b = String> {} | 130 | struct Defaulted<'a, 'b: 'a, T: Debug + Clone + 'a + 'b = String, const S: usize> {} |
120 | 131 | ||
121 | impl<'a, 'b: 'a, T: Debug + Clone + 'a + 'b> Defaulted<'a, 'b, T> { | 132 | impl<'a, 'b: 'a, T: Debug + Clone + 'a + 'b, const S: usize> Defaulted<'a, 'b, T, S> { |
122 | $0 | 133 | $0 |
123 | }"#, | 134 | }"#, |
124 | ); | 135 | ); |
diff --git a/crates/ide_assists/src/handlers/generate_is_empty_from_len.rs b/crates/ide_assists/src/handlers/generate_is_empty_from_len.rs index b8834d283..910010a04 100644 --- a/crates/ide_assists/src/handlers/generate_is_empty_from_len.rs +++ b/crates/ide_assists/src/handlers/generate_is_empty_from_len.rs | |||
@@ -91,7 +91,7 @@ fn get_impl_method( | |||
91 | 91 | ||
92 | let scope = ctx.sema.scope(impl_.syntax()); | 92 | let scope = ctx.sema.scope(impl_.syntax()); |
93 | let krate = impl_def.module(db).krate(); | 93 | let krate = impl_def.module(db).krate(); |
94 | let ty = impl_def.target_ty(db); | 94 | let ty = impl_def.self_ty(db); |
95 | let traits_in_scope = scope.traits_in_scope(); | 95 | let traits_in_scope = scope.traits_in_scope(); |
96 | ty.iterate_method_candidates(db, krate, &traits_in_scope, Some(fn_name), |_, func| Some(func)) | 96 | ty.iterate_method_candidates(db, krate, &traits_in_scope, Some(fn_name), |_, func| Some(func)) |
97 | } | 97 | } |
diff --git a/crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs b/crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs index 4f0ef52ca..f872d20c8 100644 --- a/crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs +++ b/crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs | |||
@@ -165,7 +165,7 @@ fn impl_def_from_trait( | |||
165 | } | 165 | } |
166 | let impl_def = make::impl_trait( | 166 | let impl_def = make::impl_trait( |
167 | trait_path.clone(), | 167 | trait_path.clone(), |
168 | make::path_unqualified(make::path_segment(make::name_ref(annotated_name.text()))), | 168 | make::path_unqualified(make::path_segment(make::name_ref(&annotated_name.text()))), |
169 | ); | 169 | ); |
170 | let (impl_def, first_assoc_item) = | 170 | let (impl_def, first_assoc_item) = |
171 | add_trait_assoc_items_to_impl(sema, trait_items, trait_, impl_def, target_scope); | 171 | add_trait_assoc_items_to_impl(sema, trait_items, trait_, impl_def, target_scope); |
@@ -178,12 +178,13 @@ fn update_attribute( | |||
178 | trait_name: &ast::NameRef, | 178 | trait_name: &ast::NameRef, |
179 | attr: &ast::Attr, | 179 | attr: &ast::Attr, |
180 | ) { | 180 | ) { |
181 | let trait_name = trait_name.text(); | ||
181 | let new_attr_input = input | 182 | let new_attr_input = input |
182 | .syntax() | 183 | .syntax() |
183 | .descendants_with_tokens() | 184 | .descendants_with_tokens() |
184 | .filter(|t| t.kind() == IDENT) | 185 | .filter(|t| t.kind() == IDENT) |
185 | .filter_map(|t| t.into_token().map(|t| t.text().to_string())) | 186 | .filter_map(|t| t.into_token().map(|t| t.text().to_string())) |
186 | .filter(|t| t != trait_name.text()) | 187 | .filter(|t| t != &trait_name) |
187 | .collect::<Vec<_>>(); | 188 | .collect::<Vec<_>>(); |
188 | let has_more_derives = !new_attr_input.is_empty(); | 189 | let has_more_derives = !new_attr_input.is_empty(); |
189 | 190 | ||