From 30a226c72532f04033d4c283ba7c94790e2da541 Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Sat, 16 Mar 2019 23:24:17 +0100 Subject: Move the primary assist fn to the top of the file --- crates/ra_assists/src/add_missing_impl_members.rs | 60 +++++++++++------------ 1 file changed, 30 insertions(+), 30 deletions(-) (limited to 'crates/ra_assists') diff --git a/crates/ra_assists/src/add_missing_impl_members.rs b/crates/ra_assists/src/add_missing_impl_members.rs index 96dde3c4b..4435c4b5d 100644 --- a/crates/ra_assists/src/add_missing_impl_members.rs +++ b/crates/ra_assists/src/add_missing_impl_members.rs @@ -9,36 +9,6 @@ use ra_fmt::{leading_indent, reindent}; use itertools::Itertools; -/// Given an `ast::ImplBlock`, resolves the target trait (the one being -/// implemented) to a `ast::TraitDef`. -fn resolve_target_trait_def( - db: &impl HirDatabase, - resolver: &Resolver, - impl_block: &ast::ImplBlock, -) -> Option> { - let ast_path = impl_block.target_trait().map(AstNode::syntax).and_then(ast::PathType::cast)?; - let hir_path = ast_path.path().and_then(hir::Path::from_ast)?; - - match resolver.resolve_path(db, &hir_path).take_types() { - Some(hir::Resolution::Def(hir::ModuleDef::Trait(def))) => Some(def.source(db).1), - _ => None, - } -} - -fn build_func_body(def: &ast::FnDef) -> String { - let mut buf = String::new(); - - for child in def.syntax().children() { - if child.kind() == SyntaxKind::SEMI { - buf.push_str(" { unimplemented!() }") - } else { - child.text().push_to(&mut buf); - } - } - - buf.trim_end().to_string() -} - pub(crate) fn add_missing_impl_members(mut ctx: AssistCtx) -> Option { let impl_node = ctx.node_at_offset::()?; let impl_item_list = impl_node.item_list()?; @@ -113,6 +83,36 @@ pub(crate) fn add_missing_impl_members(mut ctx: AssistCtx) -> ctx.build() } +/// Given an `ast::ImplBlock`, resolves the target trait (the one being +/// implemented) to a `ast::TraitDef`. +fn resolve_target_trait_def( + db: &impl HirDatabase, + resolver: &Resolver, + impl_block: &ast::ImplBlock, +) -> Option> { + let ast_path = impl_block.target_trait().map(AstNode::syntax).and_then(ast::PathType::cast)?; + let hir_path = ast_path.path().and_then(hir::Path::from_ast)?; + + match resolver.resolve_path(db, &hir_path).take_types() { + Some(hir::Resolution::Def(hir::ModuleDef::Trait(def))) => Some(def.source(db).1), + _ => None, + } +} + +fn build_func_body(def: &ast::FnDef) -> String { + let mut buf = String::new(); + + for child in def.syntax().children() { + if child.kind() == SyntaxKind::SEMI { + buf.push_str(" { unimplemented!() }") + } else { + child.text().push_to(&mut buf); + } + } + + buf.trim_end().to_string() +} + #[cfg(test)] mod tests { use super::*; -- cgit v1.2.3