use hir::{PathResolution, Semantics};
use ide_db::RootDatabase;
use syntax::{
- ast::{self, NameOwner},
+ ast::{self, HasName},
ted, AstNode,
};
-use crate::{AssistContext, AssistId, AssistKind, Assists};
+use crate::{utils::get_methods, AssistContext, AssistId, AssistKind, Assists};
// Assist: reorder_impl
//
// fn c() {}
// }
// ```
-//
pub(crate) fn reorder_impl(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
let impl_ast = ctx.find_node_at_offset::<ast::Impl>()?;
let items = impl_ast.assoc_item_list()?;
let target = items.syntax().text_range();
acc.add(
AssistId("reorder_impl", AssistKind::RefactorRewrite),
- "Sort methods",
+ "Sort methods by trait definition",
target,
|builder| {
- let methods =
- methods.into_iter().map(|fn_| builder.make_ast_mut(fn_)).collect::<Vec<_>>();
+ let methods = methods.into_iter().map(|fn_| builder.make_mut(fn_)).collect::<Vec<_>>();
methods
.into_iter()
.zip(sorted)
}
}
-fn get_methods(items: &ast::AssocItemList) -> Vec<ast::Fn> {
- items
- .assoc_items()
- .flat_map(|i| match i {
- ast::AssocItem::Fn(f) => Some(f),
- _ => None,
- })
- .filter(|f| f.name().is_some())
- .collect()
-}
-
#[cfg(test)]
mod tests {
use crate::tests::{check_assist, check_assist_not_applicable};