From 09d3b7d7a2ae23a0463fadee9ae8cb6a0fa2c4bf Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 5 Aug 2020 19:29:24 +0200 Subject: [PATCH] align names in make --- crates/ra_assists/src/ast_transform.rs | 2 +- crates/ra_assists/src/handlers/early_return.rs | 6 +++--- .../ra_assists/src/handlers/expand_glob_import.rs | 2 +- crates/ra_assists/src/handlers/fill_match_arms.rs | 5 ++--- .../ra_assists/src/handlers/generate_function.rs | 2 +- .../src/handlers/replace_if_let_with_match.rs | 2 +- .../src/handlers/replace_let_with_if_let.rs | 4 ++-- .../src/handlers/replace_unwrap_with_match.rs | 4 ++-- crates/ra_assists/src/utils.rs | 4 ++-- crates/ra_ide/src/diagnostics.rs | 10 ++++++---- crates/ra_syntax/src/ast/edit.rs | 2 +- crates/ra_syntax/src/ast/make.rs | 14 +++++++------- 12 files changed, 29 insertions(+), 28 deletions(-) diff --git a/crates/ra_assists/src/ast_transform.rs b/crates/ra_assists/src/ast_transform.rs index 28f3f3546c..15ec75c956 100644 --- a/crates/ra_assists/src/ast_transform.rs +++ b/crates/ra_assists/src/ast_transform.rs @@ -63,7 +63,7 @@ impl<'a> SubstituteTypeParams<'a> { let default = k.default(source_scope.db)?; Some(( k, - ast::make::type_ref( + ast::make::ty( &default .display_source_code(source_scope.db, source_scope.module()?.into()) .ok()?, diff --git a/crates/ra_assists/src/handlers/early_return.rs b/crates/ra_assists/src/handlers/early_return.rs index 69852b6116..6816a2709e 100644 --- a/crates/ra_assists/src/handlers/early_return.rs +++ b/crates/ra_assists/src/handlers/early_return.rs @@ -123,7 +123,7 @@ pub(crate) fn convert_to_guarded_return(acc: &mut Assists, ctx: &AssistContext) let happy_arm = { let pat = make::tuple_struct_pat( path, - once(make::bind_pat(make::name("it")).into()), + once(make::ident_pat(make::name("it")).into()), ); let expr = { let name_ref = make::name_ref("it"); @@ -136,7 +136,7 @@ pub(crate) fn convert_to_guarded_return(acc: &mut Assists, ctx: &AssistContext) let sad_arm = make::match_arm( // FIXME: would be cool to use `None` or `Err(_)` if appropriate - once(make::placeholder_pat().into()), + once(make::wildcard_pat().into()), early_expression, ); @@ -144,7 +144,7 @@ pub(crate) fn convert_to_guarded_return(acc: &mut Assists, ctx: &AssistContext) }; let let_stmt = make::let_stmt( - make::bind_pat(make::name(&bound_ident.syntax().to_string())).into(), + make::ident_pat(make::name(&bound_ident.syntax().to_string())).into(), Some(match_expr), ); let let_stmt = let_stmt.indent(if_indent_level); diff --git a/crates/ra_assists/src/handlers/expand_glob_import.rs b/crates/ra_assists/src/handlers/expand_glob_import.rs index 69f6b36749..eb216a81a1 100644 --- a/crates/ra_assists/src/handlers/expand_glob_import.rs +++ b/crates/ra_assists/src/handlers/expand_glob_import.rs @@ -173,7 +173,7 @@ fn replace_ast( replace_node(replacement); }, ast::Use(use_item) => { - builder.replace_ast(use_item, ast::make::use_item(replacement.left_or_else(|ut| ast::make::use_tree(path, Some(ut), None, false)))); + builder.replace_ast(use_item, ast::make::use_(replacement.left_or_else(|ut| ast::make::use_tree(path, Some(ut), None, false)))); }, _ => {}, } diff --git a/crates/ra_assists/src/handlers/fill_match_arms.rs b/crates/ra_assists/src/handlers/fill_match_arms.rs index b2e14f9d7b..6698d1a27a 100644 --- a/crates/ra_assists/src/handlers/fill_match_arms.rs +++ b/crates/ra_assists/src/handlers/fill_match_arms.rs @@ -197,12 +197,11 @@ fn build_pat(db: &RootDatabase, module: hir::Module, var: hir::EnumVariant) -> O // FIXME: use HIR for this; it doesn't currently expose struct vs. tuple vs. unit variants though let pat: ast::Pat = match var.source(db).value.kind() { ast::StructKind::Tuple(field_list) => { - let pats = - iter::repeat(make::placeholder_pat().into()).take(field_list.fields().count()); + let pats = iter::repeat(make::wildcard_pat().into()).take(field_list.fields().count()); make::tuple_struct_pat(path, pats).into() } ast::StructKind::Record(field_list) => { - let pats = field_list.fields().map(|f| make::bind_pat(f.name().unwrap()).into()); + let pats = field_list.fields().map(|f| make::ident_pat(f.name().unwrap()).into()); make::record_pat(path, pats).into() } ast::StructKind::Unit => make::path_pat(path), diff --git a/crates/ra_assists/src/handlers/generate_function.rs b/crates/ra_assists/src/handlers/generate_function.rs index 56510861df..acc97e6482 100644 --- a/crates/ra_assists/src/handlers/generate_function.rs +++ b/crates/ra_assists/src/handlers/generate_function.rs @@ -142,7 +142,7 @@ impl FunctionBuilder { let fn_body = make::block_expr(vec![], Some(placeholder_expr)); let visibility = if self.needs_pub { Some(make::visibility_pub_crate()) } else { None }; let mut fn_def = - make::fn_def(visibility, self.fn_name, self.type_params, self.params, fn_body); + make::fn_(visibility, self.fn_name, self.type_params, self.params, fn_body); let leading_ws; let trailing_ws; diff --git a/crates/ra_assists/src/handlers/replace_if_let_with_match.rs b/crates/ra_assists/src/handlers/replace_if_let_with_match.rs index b7e30a7f27..ecafb74a1e 100644 --- a/crates/ra_assists/src/handlers/replace_if_let_with_match.rs +++ b/crates/ra_assists/src/handlers/replace_if_let_with_match.rs @@ -65,7 +65,7 @@ pub(crate) fn replace_if_let_with_match(acc: &mut Assists, ctx: &AssistContext) .type_of_pat(&pat) .and_then(|ty| TryEnum::from_ty(&ctx.sema, &ty)) .map(|it| it.sad_pattern()) - .unwrap_or_else(|| make::placeholder_pat().into()); + .unwrap_or_else(|| make::wildcard_pat().into()); let else_expr = unwrap_trivial_block(else_block); make::match_arm(vec![pattern], else_expr) }; diff --git a/crates/ra_assists/src/handlers/replace_let_with_if_let.rs b/crates/ra_assists/src/handlers/replace_let_with_if_let.rs index 64ad15a230..e4d436decc 100644 --- a/crates/ra_assists/src/handlers/replace_let_with_if_let.rs +++ b/crates/ra_assists/src/handlers/replace_let_with_if_let.rs @@ -50,10 +50,10 @@ pub(crate) fn replace_let_with_if_let(acc: &mut Assists, ctx: &AssistContext) -> target, |edit| { let with_placeholder: ast::Pat = match happy_variant { - None => make::placeholder_pat().into(), + None => make::wildcard_pat().into(), Some(var_name) => make::tuple_struct_pat( make::path_unqualified(make::path_segment(make::name_ref(var_name))), - once(make::placeholder_pat().into()), + once(make::wildcard_pat().into()), ) .into(), }; diff --git a/crates/ra_assists/src/handlers/replace_unwrap_with_match.rs b/crates/ra_assists/src/handlers/replace_unwrap_with_match.rs index e5a4bb23c3..d69f2c1b0e 100644 --- a/crates/ra_assists/src/handlers/replace_unwrap_with_match.rs +++ b/crates/ra_assists/src/handlers/replace_unwrap_with_match.rs @@ -52,7 +52,7 @@ pub(crate) fn replace_unwrap_with_match(acc: &mut Assists, ctx: &AssistContext) target, |builder| { let ok_path = make::path_unqualified(make::path_segment(make::name_ref(happy_variant))); - let it = make::bind_pat(make::name("a")).into(); + let it = make::ident_pat(make::name("a")).into(); let ok_tuple = make::tuple_struct_pat(ok_path, iter::once(it)).into(); let bind_path = make::path_unqualified(make::path_segment(make::name_ref("a"))); @@ -60,7 +60,7 @@ pub(crate) fn replace_unwrap_with_match(acc: &mut Assists, ctx: &AssistContext) let unreachable_call = make::expr_unreachable(); let err_arm = - make::match_arm(iter::once(make::placeholder_pat().into()), unreachable_call); + make::match_arm(iter::once(make::wildcard_pat().into()), unreachable_call); let match_arm_list = make::match_arm_list(vec![ok_arm, err_arm]); let match_expr = make::expr_match(caller.clone(), match_arm_list) diff --git a/crates/ra_assists/src/utils.rs b/crates/ra_assists/src/utils.rs index 373de273ca..54d5678d14 100644 --- a/crates/ra_assists/src/utils.rs +++ b/crates/ra_assists/src/utils.rs @@ -181,10 +181,10 @@ impl TryEnum { match self { TryEnum::Result => make::tuple_struct_pat( make::path_unqualified(make::path_segment(make::name_ref("Err"))), - iter::once(make::placeholder_pat().into()), + iter::once(make::wildcard_pat().into()), ) .into(), - TryEnum::Option => make::bind_pat(make::name("None")).into(), + TryEnum::Option => make::ident_pat(make::name("None")).into(), } } diff --git a/crates/ra_ide/src/diagnostics.rs b/crates/ra_ide/src/diagnostics.rs index dd8a7ffd9b..73c0b82754 100644 --- a/crates/ra_ide/src/diagnostics.rs +++ b/crates/ra_ide/src/diagnostics.rs @@ -78,8 +78,10 @@ pub(crate) fn diagnostics( } else { let mut field_list = d.ast(db); for f in d.missed_fields.iter() { - let field = - make::record_field(make::name_ref(&f.to_string()), Some(make::expr_unit())); + let field = make::record_expr_field( + make::name_ref(&f.to_string()), + Some(make::expr_unit()), + ); field_list = field_list.append_field(&field); } @@ -178,9 +180,9 @@ fn missing_struct_field_fix( if new_field_type.is_unknown() { return None; } - let new_field = make::record_field_def( + let new_field = make::record_field( record_expr.field_name()?, - make::type_ref(&new_field_type.display_source_code(sema.db, module.into()).ok()?), + make::ty(&new_field_type.display_source_code(sema.db, module.into()).ok()?), ); let last_field = record_fields.fields().last()?; diff --git a/crates/ra_syntax/src/ast/edit.rs b/crates/ra_syntax/src/ast/edit.rs index 667a9294fb..5ed123f91f 100644 --- a/crates/ra_syntax/src/ast/edit.rs +++ b/crates/ra_syntax/src/ast/edit.rs @@ -621,7 +621,7 @@ fn single_node(element: impl Into) -> RangeInclusive ast::NameRef { ast_from_text(&format!("fn f() {{ {}; }}", text)) } -pub fn type_ref(text: &str) -> ast::Type { +pub fn ty(text: &str) -> ast::Type { ast_from_text(&format!("impl {} for D {{}};", text)) } @@ -60,11 +60,11 @@ pub fn use_tree_list(use_trees: impl IntoIterator) -> ast:: ast_from_text(&format!("use {{{}}};", use_trees)) } -pub fn use_item(use_tree: ast::UseTree) -> ast::Use { +pub fn use_(use_tree: ast::UseTree) -> ast::Use { ast_from_text(&format!("use {};", use_tree)) } -pub fn record_field(name: ast::NameRef, expr: Option) -> ast::RecordExprField { +pub fn record_expr_field(name: ast::NameRef, expr: Option) -> ast::RecordExprField { return match expr { Some(expr) => from_text(&format!("{}: {}", name, expr)), None => from_text(&name.to_string()), @@ -75,7 +75,7 @@ pub fn record_field(name: ast::NameRef, expr: Option) -> ast::RecordE } } -pub fn record_field_def(name: ast::NameRef, ty: ast::Type) -> ast::RecordField { +pub fn record_field(name: ast::NameRef, ty: ast::Type) -> ast::RecordField { ast_from_text(&format!("struct S {{ {}: {}, }}", name, ty)) } @@ -148,7 +148,7 @@ pub fn condition(expr: ast::Expr, pattern: Option) -> ast::Condition { } } -pub fn bind_pat(name: ast::Name) -> ast::IdentPat { +pub fn ident_pat(name: ast::Name) -> ast::IdentPat { return from_text(name.text()); fn from_text(text: &str) -> ast::IdentPat { @@ -156,7 +156,7 @@ pub fn bind_pat(name: ast::Name) -> ast::IdentPat { } } -pub fn placeholder_pat() -> ast::WildcardPat { +pub fn wildcard_pat() -> ast::WildcardPat { return from_text("_"); fn from_text(text: &str) -> ast::WildcardPat { @@ -288,7 +288,7 @@ pub fn visibility_pub_crate() -> ast::Visibility { ast_from_text("pub(crate) struct S") } -pub fn fn_def( +pub fn fn_( visibility: Option, fn_name: ast::Name, type_params: Option,