11001: minor: fixup generate assist priorities r=Veykril a=Veykril

Fixes https://github.com/rust-analyzer/rust-analyzer/issues/10996
bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
bors[bot] 2021-12-13 15:51:54 +00:00 committed by GitHub
commit e1f3982a5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 7 deletions

View File

@ -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::<ast::RecordField>() {
let (field_name, field_ty, target) = match ctx.find_node_at_offset::<ast::RecordField>() {
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::<ast::TupleField>()?;
let field_list = ctx.find_node_at_offset::<ast::TupleFieldList>()?;
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();

View File

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

View File

@ -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]`");
}