diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_assists/src/add_missing_impl_members.rs | 60 |
1 files changed, 30 insertions, 30 deletions
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}; | |||
9 | 9 | ||
10 | use itertools::Itertools; | 10 | use itertools::Itertools; |
11 | 11 | ||
12 | /// Given an `ast::ImplBlock`, resolves the target trait (the one being | ||
13 | /// implemented) to a `ast::TraitDef`. | ||
14 | fn resolve_target_trait_def( | ||
15 | db: &impl HirDatabase, | ||
16 | resolver: &Resolver, | ||
17 | impl_block: &ast::ImplBlock, | ||
18 | ) -> Option<TreeArc<ast::TraitDef>> { | ||
19 | let ast_path = impl_block.target_trait().map(AstNode::syntax).and_then(ast::PathType::cast)?; | ||
20 | let hir_path = ast_path.path().and_then(hir::Path::from_ast)?; | ||
21 | |||
22 | match resolver.resolve_path(db, &hir_path).take_types() { | ||
23 | Some(hir::Resolution::Def(hir::ModuleDef::Trait(def))) => Some(def.source(db).1), | ||
24 | _ => None, | ||
25 | } | ||
26 | } | ||
27 | |||
28 | fn build_func_body(def: &ast::FnDef) -> String { | ||
29 | let mut buf = String::new(); | ||
30 | |||
31 | for child in def.syntax().children() { | ||
32 | if child.kind() == SyntaxKind::SEMI { | ||
33 | buf.push_str(" { unimplemented!() }") | ||
34 | } else { | ||
35 | child.text().push_to(&mut buf); | ||
36 | } | ||
37 | } | ||
38 | |||
39 | buf.trim_end().to_string() | ||
40 | } | ||
41 | |||
42 | pub(crate) fn add_missing_impl_members(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { | 12 | pub(crate) fn add_missing_impl_members(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { |
43 | let impl_node = ctx.node_at_offset::<ast::ImplBlock>()?; | 13 | let impl_node = ctx.node_at_offset::<ast::ImplBlock>()?; |
44 | let impl_item_list = impl_node.item_list()?; | 14 | let impl_item_list = impl_node.item_list()?; |
@@ -113,6 +83,36 @@ pub(crate) fn add_missing_impl_members(mut ctx: AssistCtx<impl HirDatabase>) -> | |||
113 | ctx.build() | 83 | ctx.build() |
114 | } | 84 | } |
115 | 85 | ||
86 | /// Given an `ast::ImplBlock`, resolves the target trait (the one being | ||
87 | /// implemented) to a `ast::TraitDef`. | ||
88 | fn resolve_target_trait_def( | ||
89 | db: &impl HirDatabase, | ||
90 | resolver: &Resolver, | ||
91 | impl_block: &ast::ImplBlock, | ||
92 | ) -> Option<TreeArc<ast::TraitDef>> { | ||
93 | let ast_path = impl_block.target_trait().map(AstNode::syntax).and_then(ast::PathType::cast)?; | ||
94 | let hir_path = ast_path.path().and_then(hir::Path::from_ast)?; | ||
95 | |||
96 | match resolver.resolve_path(db, &hir_path).take_types() { | ||
97 | Some(hir::Resolution::Def(hir::ModuleDef::Trait(def))) => Some(def.source(db).1), | ||
98 | _ => None, | ||
99 | } | ||
100 | } | ||
101 | |||
102 | fn build_func_body(def: &ast::FnDef) -> String { | ||
103 | let mut buf = String::new(); | ||
104 | |||
105 | for child in def.syntax().children() { | ||
106 | if child.kind() == SyntaxKind::SEMI { | ||
107 | buf.push_str(" { unimplemented!() }") | ||
108 | } else { | ||
109 | child.text().push_to(&mut buf); | ||
110 | } | ||
111 | } | ||
112 | |||
113 | buf.trim_end().to_string() | ||
114 | } | ||
115 | |||
116 | #[cfg(test)] | 116 | #[cfg(test)] |
117 | mod tests { | 117 | mod tests { |
118 | use super::*; | 118 | use super::*; |