diff --git a/crates/ide_assists/src/handlers/generate_delegate_methods.rs b/crates/ide_assists/src/handlers/generate_delegate_methods.rs index 090dab946ab..31b438b15ec 100644 --- a/crates/ide_assists/src/handlers/generate_delegate_methods.rs +++ b/crates/ide_assists/src/handlers/generate_delegate_methods.rs @@ -47,18 +47,18 @@ pub(crate) fn generate_delegate_methods(acc: &mut Assists, ctx: &AssistContext) let strukt_name = strukt.name()?; let current_module = ctx.sema.scope(strukt.syntax()).module()?; - let (field_name, field_ty) = match ctx.find_node_at_offset::() { + let (field_name, field_ty, target) = match ctx.find_node_at_offset::() { Some(field) => { let field_name = field.name()?; let field_ty = field.ty()?; - (format!("{}", field_name), field_ty) + (format!("{}", field_name), field_ty, field.syntax().text_range()) } None => { let field = ctx.find_node_at_offset::()?; let field_list = ctx.find_node_at_offset::()?; let field_list_index = field_list.fields().position(|it| it == field)?; let field_ty = field.ty()?; - (format!("{}", field_list_index), field_ty) + (format!("{}", field_list_index), field_ty, field.syntax().text_range()) } }; @@ -74,7 +74,6 @@ pub(crate) fn generate_delegate_methods(acc: &mut Assists, ctx: &AssistContext) Option::<()>::None }); - let target = field_ty.syntax().text_range(); for method in methods { let adt = ast::Adt::Struct(strukt.clone()); let name = method.name(ctx.db()).to_string(); diff --git a/crates/ide_assists/src/lib.rs b/crates/ide_assists/src/lib.rs index 61ac45637be..a1dfa065ff8 100644 --- a/crates/ide_assists/src/lib.rs +++ b/crates/ide_assists/src/lib.rs @@ -217,8 +217,6 @@ pub(crate) fn all() -> &'static [Handler] { generate_constant::generate_constant, generate_default_from_enum_variant::generate_default_from_enum_variant, generate_default_from_new::generate_default_from_new, - generate_delegate_methods::generate_delegate_methods, - generate_deref::generate_deref, generate_derive::generate_derive, generate_documentation_template::generate_documentation_template, generate_enum_is_method::generate_enum_is_method, @@ -287,6 +285,8 @@ pub(crate) fn all() -> &'static [Handler] { generate_getter::generate_getter, generate_getter::generate_getter_mut, generate_setter::generate_setter, + generate_delegate_methods::generate_delegate_methods, + generate_deref::generate_deref, // Are you sure you want to add new assist here, and not to the // sorted list above? ] diff --git a/crates/ide_assists/src/tests.rs b/crates/ide_assists/src/tests.rs index 5a799795333..08947e4ecd8 100644 --- a/crates/ide_assists/src/tests.rs +++ b/crates/ide_assists/src/tests.rs @@ -222,10 +222,10 @@ fn assist_order_field_struct() { let mut assists = assists.iter(); assert_eq!(assists.next().expect("expected assist").label, "Change visibility to pub(crate)"); - assert_eq!(assists.next().expect("expected assist").label, "Generate `Deref` impl using `bar`"); assert_eq!(assists.next().expect("expected assist").label, "Generate a getter method"); assert_eq!(assists.next().expect("expected assist").label, "Generate a mut getter method"); assert_eq!(assists.next().expect("expected assist").label, "Generate a setter method"); + assert_eq!(assists.next().expect("expected assist").label, "Generate `Deref` impl using `bar`"); assert_eq!(assists.next().expect("expected assist").label, "Add `#[derive]`"); }