From 2984da672e0c73d56501c6b6e4d19fd28152b5eb Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 11:42:51 +0200 Subject: Split ItemList & AssocItemList --- crates/ra_assists/src/handlers/generate_new.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_assists/src/handlers/generate_new.rs') diff --git a/crates/ra_assists/src/handlers/generate_new.rs b/crates/ra_assists/src/handlers/generate_new.rs index e27def1d8..25bc171bf 100644 --- a/crates/ra_assists/src/handlers/generate_new.rs +++ b/crates/ra_assists/src/handlers/generate_new.rs @@ -158,7 +158,7 @@ fn find_struct_impl(ctx: &AssistContext, strukt: &ast::StructDef) -> Option bool { - if let Some(il) = imp.item_list() { + if let Some(il) = imp.assoc_item_list() { for item in il.assoc_items() { if let ast::AssocItem::FnDef(f) = item { if let Some(name) = f.name() { -- cgit v1.2.3 From 1142112c70b705f59b7d559d9d72cdc831865158 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 14:51:08 +0200 Subject: Rename FnDef -> Fn --- crates/ra_assists/src/handlers/generate_new.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_assists/src/handlers/generate_new.rs') diff --git a/crates/ra_assists/src/handlers/generate_new.rs b/crates/ra_assists/src/handlers/generate_new.rs index 25bc171bf..4dff0ae4d 100644 --- a/crates/ra_assists/src/handlers/generate_new.rs +++ b/crates/ra_assists/src/handlers/generate_new.rs @@ -160,7 +160,7 @@ fn find_struct_impl(ctx: &AssistContext, strukt: &ast::StructDef) -> Option bool { if let Some(il) = imp.assoc_item_list() { for item in il.assoc_items() { - if let ast::AssocItem::FnDef(f) = item { + if let ast::AssocItem::Fn(f) = item { if let Some(name) = f.name() { if name.text().eq_ignore_ascii_case("new") { return true; -- cgit v1.2.3 From 28ef4c375a9f56d69daf885504aea3df7012bb81 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 15:36:21 +0200 Subject: Rename TypeParamList -> GenericParamList --- crates/ra_assists/src/handlers/generate_new.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'crates/ra_assists/src/handlers/generate_new.rs') diff --git a/crates/ra_assists/src/handlers/generate_new.rs b/crates/ra_assists/src/handlers/generate_new.rs index 4dff0ae4d..340f9b103 100644 --- a/crates/ra_assists/src/handlers/generate_new.rs +++ b/crates/ra_assists/src/handlers/generate_new.rs @@ -1,7 +1,8 @@ use hir::Adt; use ra_syntax::{ ast::{ - self, AstNode, NameOwner, StructKind, TypeAscriptionOwner, TypeParamsOwner, VisibilityOwner, + self, AstNode, GenericParamsOwner, NameOwner, StructKind, TypeAscriptionOwner, + VisibilityOwner, }, T, }; @@ -91,7 +92,7 @@ pub(crate) fn generate_new(acc: &mut Assists, ctx: &AssistContext) -> Option<()> // Generates the surrounding `impl Type { }` including type and lifetime // parameters fn generate_impl_text(strukt: &ast::StructDef, code: &str) -> String { - let type_params = strukt.type_param_list(); + let type_params = strukt.generic_param_list(); let mut buf = String::with_capacity(code.len()); buf.push_str("\n\nimpl"); if let Some(type_params) = &type_params { -- cgit v1.2.3 From 216a5344c8ef3c3e430d2761dc8b1a7b60250a15 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 17:50:40 +0200 Subject: Rename StructDef -> Struct --- crates/ra_assists/src/handlers/generate_new.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'crates/ra_assists/src/handlers/generate_new.rs') diff --git a/crates/ra_assists/src/handlers/generate_new.rs b/crates/ra_assists/src/handlers/generate_new.rs index 340f9b103..22b47d254 100644 --- a/crates/ra_assists/src/handlers/generate_new.rs +++ b/crates/ra_assists/src/handlers/generate_new.rs @@ -31,7 +31,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists}; // // ``` pub(crate) fn generate_new(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { - let strukt = ctx.find_node_at_offset::()?; + let strukt = ctx.find_node_at_offset::()?; // We want to only apply this to non-union structs with named fields let field_list = match strukt.kind() { @@ -91,7 +91,7 @@ pub(crate) fn generate_new(acc: &mut Assists, ctx: &AssistContext) -> Option<()> // Generates the surrounding `impl Type { }` including type and lifetime // parameters -fn generate_impl_text(strukt: &ast::StructDef, code: &str) -> String { +fn generate_impl_text(strukt: &ast::Struct, code: &str) -> String { let type_params = strukt.generic_param_list(); let mut buf = String::with_capacity(code.len()); buf.push_str("\n\nimpl"); @@ -122,7 +122,7 @@ fn generate_impl_text(strukt: &ast::StructDef, code: &str) -> String { // // FIXME: change the new fn checking to a more semantic approach when that's more // viable (e.g. we process proc macros, etc) -fn find_struct_impl(ctx: &AssistContext, strukt: &ast::StructDef) -> Option> { +fn find_struct_impl(ctx: &AssistContext, strukt: &ast::Struct) -> Option> { let db = ctx.db(); let module = strukt.syntax().ancestors().find(|node| { ast::Module::can_cast(node.kind()) || ast::SourceFile::can_cast(node.kind()) -- cgit v1.2.3 From c5798c4d75aa807aec47208a49101bdec3affcca Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 18:28:28 +0200 Subject: Finalize impl Grammar --- crates/ra_assists/src/handlers/generate_new.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'crates/ra_assists/src/handlers/generate_new.rs') diff --git a/crates/ra_assists/src/handlers/generate_new.rs b/crates/ra_assists/src/handlers/generate_new.rs index 22b47d254..3c67749ee 100644 --- a/crates/ra_assists/src/handlers/generate_new.rs +++ b/crates/ra_assists/src/handlers/generate_new.rs @@ -122,7 +122,7 @@ fn generate_impl_text(strukt: &ast::Struct, code: &str) -> String { // // FIXME: change the new fn checking to a more semantic approach when that's more // viable (e.g. we process proc macros, etc) -fn find_struct_impl(ctx: &AssistContext, strukt: &ast::Struct) -> Option> { +fn find_struct_impl(ctx: &AssistContext, strukt: &ast::Struct) -> Option> { let db = ctx.db(); let module = strukt.syntax().ancestors().find(|node| { ast::Module::can_cast(node.kind()) || ast::SourceFile::can_cast(node.kind()) @@ -130,7 +130,7 @@ fn find_struct_impl(ctx: &AssistContext, strukt: &ast::Struct) -> Option; impl S {}` @@ -158,7 +158,7 @@ fn find_struct_impl(ctx: &AssistContext, strukt: &ast::Struct) -> Option bool { +fn has_new_fn(imp: &ast::Impl) -> bool { if let Some(il) = imp.assoc_item_list() { for item in il.assoc_items() { if let ast::AssocItem::Fn(f) = item { -- cgit v1.2.3 From 2e2642efccd5855e4158b01a006e7884a96982bb Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 20:51:43 +0200 Subject: Remove TypeAscriptionOwner --- crates/ra_assists/src/handlers/generate_new.rs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'crates/ra_assists/src/handlers/generate_new.rs') diff --git a/crates/ra_assists/src/handlers/generate_new.rs b/crates/ra_assists/src/handlers/generate_new.rs index 3c67749ee..b84aa24b6 100644 --- a/crates/ra_assists/src/handlers/generate_new.rs +++ b/crates/ra_assists/src/handlers/generate_new.rs @@ -1,9 +1,6 @@ use hir::Adt; use ra_syntax::{ - ast::{ - self, AstNode, GenericParamsOwner, NameOwner, StructKind, TypeAscriptionOwner, - VisibilityOwner, - }, + ast::{self, AstNode, GenericParamsOwner, NameOwner, StructKind, VisibilityOwner}, T, }; use stdx::{format_to, SepBy}; @@ -54,9 +51,7 @@ pub(crate) fn generate_new(acc: &mut Assists, ctx: &AssistContext) -> Option<()> let params = field_list .fields() - .filter_map(|f| { - Some(format!("{}: {}", f.name()?.syntax(), f.ascribed_type()?.syntax())) - }) + .filter_map(|f| Some(format!("{}: {}", f.name()?.syntax(), f.ty()?.syntax()))) .sep_by(", "); let fields = field_list.fields().filter_map(|f| f.name()).sep_by(", "); -- cgit v1.2.3