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/introduce_named_lifetime.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ra_assists/src/handlers/introduce_named_lifetime.rs') diff --git a/crates/ra_assists/src/handlers/introduce_named_lifetime.rs b/crates/ra_assists/src/handlers/introduce_named_lifetime.rs index 967593031..f3774fab1 100644 --- a/crates/ra_assists/src/handlers/introduce_named_lifetime.rs +++ b/crates/ra_assists/src/handlers/introduce_named_lifetime.rs @@ -38,7 +38,7 @@ pub(crate) fn introduce_named_lifetime(acc: &mut Assists, ctx: &AssistContext) - let lifetime_token = ctx .find_token_at_offset(SyntaxKind::LIFETIME) .filter(|lifetime| lifetime.text() == "'_")?; - if let Some(fn_def) = lifetime_token.ancestors().find_map(ast::FnDef::cast) { + if let Some(fn_def) = lifetime_token.ancestors().find_map(ast::Fn::cast) { generate_fn_def_assist(acc, &fn_def, lifetime_token.text_range()) } else if let Some(impl_def) = lifetime_token.ancestors().find_map(ast::ImplDef::cast) { generate_impl_def_assist(acc, &impl_def, lifetime_token.text_range()) @@ -50,7 +50,7 @@ pub(crate) fn introduce_named_lifetime(acc: &mut Assists, ctx: &AssistContext) - /// Generate the assist for the fn def case fn generate_fn_def_assist( acc: &mut Assists, - fn_def: &ast::FnDef, + fn_def: &ast::Fn, lifetime_loc: TextRange, ) -> Option<()> { let param_list: ast::ParamList = fn_def.param_list()?; -- 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/introduce_named_lifetime.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'crates/ra_assists/src/handlers/introduce_named_lifetime.rs') diff --git a/crates/ra_assists/src/handlers/introduce_named_lifetime.rs b/crates/ra_assists/src/handlers/introduce_named_lifetime.rs index f3774fab1..4ad173ef0 100644 --- a/crates/ra_assists/src/handlers/introduce_named_lifetime.rs +++ b/crates/ra_assists/src/handlers/introduce_named_lifetime.rs @@ -1,5 +1,5 @@ use ra_syntax::{ - ast::{self, NameOwner, TypeAscriptionOwner, TypeParamsOwner}, + ast::{self, GenericParamsOwner, NameOwner, TypeAscriptionOwner}, AstNode, SyntaxKind, TextRange, TextSize, }; use rustc_hash::FxHashSet; @@ -54,7 +54,7 @@ fn generate_fn_def_assist( lifetime_loc: TextRange, ) -> Option<()> { let param_list: ast::ParamList = fn_def.param_list()?; - let new_lifetime_param = generate_unique_lifetime_param_name(&fn_def.type_param_list())?; + let new_lifetime_param = generate_unique_lifetime_param_name(&fn_def.generic_param_list())?; let end_of_fn_ident = fn_def.name()?.ident_token()?.text_range().end(); let self_param = // use the self if it's a reference and has no explicit lifetime @@ -96,7 +96,7 @@ fn generate_impl_def_assist( impl_def: &ast::ImplDef, lifetime_loc: TextRange, ) -> Option<()> { - let new_lifetime_param = generate_unique_lifetime_param_name(&impl_def.type_param_list())?; + let new_lifetime_param = generate_unique_lifetime_param_name(&impl_def.generic_param_list())?; let end_of_impl_kw = impl_def.impl_token()?.text_range().end(); acc.add(AssistId(ASSIST_NAME, AssistKind::Refactor), ASSIST_LABEL, lifetime_loc, |builder| { add_lifetime_param(impl_def, builder, end_of_impl_kw, new_lifetime_param); @@ -107,7 +107,7 @@ fn generate_impl_def_assist( /// Given a type parameter list, generate a unique lifetime parameter name /// which is not in the list fn generate_unique_lifetime_param_name( - existing_type_param_list: &Option, + existing_type_param_list: &Option, ) -> Option { match existing_type_param_list { Some(type_params) => { @@ -123,13 +123,13 @@ fn generate_unique_lifetime_param_name( /// Add the lifetime param to `builder`. If there are type parameters in `type_params_owner`, add it to the end. Otherwise /// add new type params brackets with the lifetime parameter at `new_type_params_loc`. -fn add_lifetime_param( +fn add_lifetime_param( type_params_owner: &TypeParamsOwner, builder: &mut AssistBuilder, new_type_params_loc: TextSize, new_lifetime_param: char, ) { - match type_params_owner.type_param_list() { + match type_params_owner.generic_param_list() { // add the new lifetime parameter to an existing type param list Some(type_params) => { builder.insert( -- 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/introduce_named_lifetime.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ra_assists/src/handlers/introduce_named_lifetime.rs') diff --git a/crates/ra_assists/src/handlers/introduce_named_lifetime.rs b/crates/ra_assists/src/handlers/introduce_named_lifetime.rs index 4ad173ef0..92a1a5925 100644 --- a/crates/ra_assists/src/handlers/introduce_named_lifetime.rs +++ b/crates/ra_assists/src/handlers/introduce_named_lifetime.rs @@ -40,7 +40,7 @@ pub(crate) fn introduce_named_lifetime(acc: &mut Assists, ctx: &AssistContext) - .filter(|lifetime| lifetime.text() == "'_")?; if let Some(fn_def) = lifetime_token.ancestors().find_map(ast::Fn::cast) { generate_fn_def_assist(acc, &fn_def, lifetime_token.text_range()) - } else if let Some(impl_def) = lifetime_token.ancestors().find_map(ast::ImplDef::cast) { + } else if let Some(impl_def) = lifetime_token.ancestors().find_map(ast::Impl::cast) { generate_impl_def_assist(acc, &impl_def, lifetime_token.text_range()) } else { None @@ -93,7 +93,7 @@ fn generate_fn_def_assist( /// Generate the assist for the impl def case fn generate_impl_def_assist( acc: &mut Assists, - impl_def: &ast::ImplDef, + impl_def: &ast::Impl, lifetime_loc: TextRange, ) -> Option<()> { let new_lifetime_param = generate_unique_lifetime_param_name(&impl_def.generic_param_list())?; -- 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/introduce_named_lifetime.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ra_assists/src/handlers/introduce_named_lifetime.rs') diff --git a/crates/ra_assists/src/handlers/introduce_named_lifetime.rs b/crates/ra_assists/src/handlers/introduce_named_lifetime.rs index 92a1a5925..c3134f64d 100644 --- a/crates/ra_assists/src/handlers/introduce_named_lifetime.rs +++ b/crates/ra_assists/src/handlers/introduce_named_lifetime.rs @@ -1,5 +1,5 @@ use ra_syntax::{ - ast::{self, GenericParamsOwner, NameOwner, TypeAscriptionOwner}, + ast::{self, GenericParamsOwner, NameOwner}, AstNode, SyntaxKind, TextRange, TextSize, }; use rustc_hash::FxHashSet; @@ -67,7 +67,7 @@ fn generate_fn_def_assist( // otherwise, if there's a single reference parameter without a named liftime, use that let fn_params_without_lifetime: Vec<_> = param_list .params() - .filter_map(|param| match param.ascribed_type() { + .filter_map(|param| match param.ty() { Some(ast::TypeRef::ReferenceType(ascribed_type)) if ascribed_type.lifetime_token() == None => { -- cgit v1.2.3 From 08ea2271e8050165d0aaf4c994ed3dd746aff3ba Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 31 Jul 2020 12:06:38 +0200 Subject: Rename TypeRef -> Type The TypeRef name comes from IntelliJ days, where you often have both type *syntax* as well as *semantical* representation of types in scope. And naming both Type is confusing. In rust-analyzer however, we use ast types as `ast::Type`, and have many more semantic counterparts to ast types, so avoiding name clash here is just confusing. --- crates/ra_assists/src/handlers/introduce_named_lifetime.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_assists/src/handlers/introduce_named_lifetime.rs') diff --git a/crates/ra_assists/src/handlers/introduce_named_lifetime.rs b/crates/ra_assists/src/handlers/introduce_named_lifetime.rs index c3134f64d..4537c73a1 100644 --- a/crates/ra_assists/src/handlers/introduce_named_lifetime.rs +++ b/crates/ra_assists/src/handlers/introduce_named_lifetime.rs @@ -68,7 +68,7 @@ fn generate_fn_def_assist( let fn_params_without_lifetime: Vec<_> = param_list .params() .filter_map(|param| match param.ty() { - Some(ast::TypeRef::ReferenceType(ascribed_type)) + Some(ast::Type::ReferenceType(ascribed_type)) if ascribed_type.lifetime_token() == None => { Some(ascribed_type.amp_token()?.text_range().end()) -- cgit v1.2.3 From bff8dd094958f1abe2fcfe8fe9f15dc7a7e6b53e Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 1 Aug 2020 13:47:19 +0200 Subject: Update grammar --- crates/ra_assists/src/handlers/introduce_named_lifetime.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_assists/src/handlers/introduce_named_lifetime.rs') diff --git a/crates/ra_assists/src/handlers/introduce_named_lifetime.rs b/crates/ra_assists/src/handlers/introduce_named_lifetime.rs index 4537c73a1..fbaf3c06b 100644 --- a/crates/ra_assists/src/handlers/introduce_named_lifetime.rs +++ b/crates/ra_assists/src/handlers/introduce_named_lifetime.rs @@ -68,7 +68,7 @@ fn generate_fn_def_assist( let fn_params_without_lifetime: Vec<_> = param_list .params() .filter_map(|param| match param.ty() { - Some(ast::Type::ReferenceType(ascribed_type)) + Some(ast::Type::RefType(ascribed_type)) if ascribed_type.lifetime_token() == None => { Some(ascribed_type.amp_token()?.text_range().end()) -- cgit v1.2.3