aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists/src/handlers/add_new.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_assists/src/handlers/add_new.rs')
-rw-r--r--crates/ra_assists/src/handlers/add_new.rs16
1 files changed, 8 insertions, 8 deletions
diff --git a/crates/ra_assists/src/handlers/add_new.rs b/crates/ra_assists/src/handlers/add_new.rs
index 166e907fb..697e7cda6 100644
--- a/crates/ra_assists/src/handlers/add_new.rs
+++ b/crates/ra_assists/src/handlers/add_new.rs
@@ -41,14 +41,14 @@ pub(crate) fn add_new(ctx: AssistCtx) -> Option<Assist> {
41 }; 41 };
42 42
43 // Return early if we've found an existing new fn 43 // Return early if we've found an existing new fn
44 let impl_block = find_struct_impl(&ctx, &strukt)?; 44 let impl_def = find_struct_impl(&ctx, &strukt)?;
45 45
46 ctx.add_assist(AssistId("add_new"), "Add default constructor", |edit| { 46 ctx.add_assist(AssistId("add_new"), "Add default constructor", |edit| {
47 edit.target(strukt.syntax().text_range()); 47 edit.target(strukt.syntax().text_range());
48 48
49 let mut buf = String::with_capacity(512); 49 let mut buf = String::with_capacity(512);
50 50
51 if impl_block.is_some() { 51 if impl_def.is_some() {
52 buf.push('\n'); 52 buf.push('\n');
53 } 53 }
54 54
@@ -71,10 +71,10 @@ pub(crate) fn add_new(ctx: AssistCtx) -> Option<Assist> {
71 71
72 buf.push_str("} }"); 72 buf.push_str("} }");
73 73
74 let (start_offset, end_offset) = impl_block 74 let (start_offset, end_offset) = impl_def
75 .and_then(|impl_block| { 75 .and_then(|impl_def| {
76 buf.push('\n'); 76 buf.push('\n');
77 let start = impl_block 77 let start = impl_def
78 .syntax() 78 .syntax()
79 .descendants_with_tokens() 79 .descendants_with_tokens()
80 .find(|t| t.kind() == T!['{'])? 80 .find(|t| t.kind() == T!['{'])?
@@ -128,7 +128,7 @@ fn generate_impl_text(strukt: &ast::StructDef, code: &str) -> String {
128// 128//
129// FIXME: change the new fn checking to a more semantic approach when that's more 129// FIXME: change the new fn checking to a more semantic approach when that's more
130// viable (e.g. we process proc macros, etc) 130// viable (e.g. we process proc macros, etc)
131fn find_struct_impl(ctx: &AssistCtx, strukt: &ast::StructDef) -> Option<Option<ast::ImplBlock>> { 131fn find_struct_impl(ctx: &AssistCtx, strukt: &ast::StructDef) -> Option<Option<ast::ImplDef>> {
132 let db = ctx.db; 132 let db = ctx.db;
133 let module = strukt.syntax().ancestors().find(|node| { 133 let module = strukt.syntax().ancestors().find(|node| {
134 ast::Module::can_cast(node.kind()) || ast::SourceFile::can_cast(node.kind()) 134 ast::Module::can_cast(node.kind()) || ast::SourceFile::can_cast(node.kind())
@@ -136,7 +136,7 @@ fn find_struct_impl(ctx: &AssistCtx, strukt: &ast::StructDef) -> Option<Option<a
136 136
137 let struct_def = ctx.sema.to_def(strukt)?; 137 let struct_def = ctx.sema.to_def(strukt)?;
138 138
139 let block = module.descendants().filter_map(ast::ImplBlock::cast).find_map(|impl_blk| { 139 let block = module.descendants().filter_map(ast::ImplDef::cast).find_map(|impl_blk| {
140 let blk = ctx.sema.to_def(&impl_blk)?; 140 let blk = ctx.sema.to_def(&impl_blk)?;
141 141
142 // FIXME: handle e.g. `struct S<T>; impl<U> S<U> {}` 142 // FIXME: handle e.g. `struct S<T>; impl<U> S<U> {}`
@@ -164,7 +164,7 @@ fn find_struct_impl(ctx: &AssistCtx, strukt: &ast::StructDef) -> Option<Option<a
164 Some(block) 164 Some(block)
165} 165}
166 166
167fn has_new_fn(imp: &ast::ImplBlock) -> bool { 167fn has_new_fn(imp: &ast::ImplDef) -> bool {
168 if let Some(il) = imp.item_list() { 168 if let Some(il) = imp.item_list() {
169 for item in il.impl_items() { 169 for item in il.impl_items() {
170 if let ast::ImplItem::FnDef(f) = item { 170 if let ast::ImplItem::FnDef(f) = item {