diff options
Diffstat (limited to 'crates/ra_assists/src/assists')
-rw-r--r-- | crates/ra_assists/src/assists/add_missing_impl_members.rs | 7 | ||||
-rw-r--r-- | crates/ra_assists/src/assists/fill_match_arms.rs | 27 | ||||
-rw-r--r-- | crates/ra_assists/src/assists/move_bounds.rs | 10 |
3 files changed, 23 insertions, 21 deletions
diff --git a/crates/ra_assists/src/assists/add_missing_impl_members.rs b/crates/ra_assists/src/assists/add_missing_impl_members.rs index 22d20909d..23da1e65f 100644 --- a/crates/ra_assists/src/assists/add_missing_impl_members.rs +++ b/crates/ra_assists/src/assists/add_missing_impl_members.rs | |||
@@ -1,10 +1,10 @@ | |||
1 | use hir::{db::HirDatabase, HasSource}; | 1 | use hir::{db::HirDatabase, HasSource}; |
2 | use ra_syntax::{ | 2 | use ra_syntax::{ |
3 | ast::{self, AstNode, NameOwner}, | 3 | ast::{self, make, AstNode, NameOwner}, |
4 | SmolStr, | 4 | SmolStr, |
5 | }; | 5 | }; |
6 | 6 | ||
7 | use crate::{ast_builder::Make, ast_editor::AstEditor, Assist, AssistCtx, AssistId}; | 7 | use crate::{ast_editor::AstEditor, Assist, AssistCtx, AssistId}; |
8 | 8 | ||
9 | #[derive(PartialEq)] | 9 | #[derive(PartialEq)] |
10 | enum AddMissingImplMembersMode { | 10 | enum AddMissingImplMembersMode { |
@@ -102,7 +102,8 @@ fn strip_docstring(item: ast::ImplItem) -> ast::ImplItem { | |||
102 | fn add_body(fn_def: ast::FnDef) -> ast::FnDef { | 102 | fn add_body(fn_def: ast::FnDef) -> ast::FnDef { |
103 | let mut ast_editor = AstEditor::new(fn_def.clone()); | 103 | let mut ast_editor = AstEditor::new(fn_def.clone()); |
104 | if fn_def.body().is_none() { | 104 | if fn_def.body().is_none() { |
105 | ast_editor.set_body(&Make::<ast::Block>::single_expr(Make::<ast::Expr>::unimplemented())); | 105 | let body = make::block_from_expr(make::expr_unimplemented()); |
106 | ast_editor.set_body(&body); | ||
106 | } | 107 | } |
107 | ast_editor.ast().to_owned() | 108 | ast_editor.ast().to_owned() |
108 | } | 109 | } |
diff --git a/crates/ra_assists/src/assists/fill_match_arms.rs b/crates/ra_assists/src/assists/fill_match_arms.rs index 817433526..db82db89a 100644 --- a/crates/ra_assists/src/assists/fill_match_arms.rs +++ b/crates/ra_assists/src/assists/fill_match_arms.rs | |||
@@ -1,9 +1,9 @@ | |||
1 | use std::iter; | 1 | use std::iter; |
2 | 2 | ||
3 | use hir::{db::HirDatabase, Adt, HasSource}; | 3 | use hir::{db::HirDatabase, Adt, HasSource}; |
4 | use ra_syntax::ast::{self, AstNode, NameOwner}; | 4 | use ra_syntax::ast::{self, make, AstNode, NameOwner}; |
5 | 5 | ||
6 | use crate::{ast_builder::Make, Assist, AssistCtx, AssistId}; | 6 | use crate::{Assist, AssistCtx, AssistId}; |
7 | 7 | ||
8 | pub(crate) fn fill_match_arms(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { | 8 | pub(crate) fn fill_match_arms(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { |
9 | let match_expr = ctx.node_at_offset::<ast::MatchExpr>()?; | 9 | let match_expr = ctx.node_at_offset::<ast::MatchExpr>()?; |
@@ -31,8 +31,8 @@ pub(crate) fn fill_match_arms(mut ctx: AssistCtx<impl HirDatabase>) -> Option<As | |||
31 | let variants = variant_list.variants(); | 31 | let variants = variant_list.variants(); |
32 | let arms = variants | 32 | let arms = variants |
33 | .filter_map(build_pat) | 33 | .filter_map(build_pat) |
34 | .map(|pat| Make::<ast::MatchArm>::from(iter::once(pat), Make::<ast::Expr>::unit())); | 34 | .map(|pat| make::match_arm(iter::once(pat), make::expr_unit())); |
35 | let new_arm_list = Make::<ast::MatchArmList>::from_arms(arms); | 35 | let new_arm_list = make::match_arm_list(arms); |
36 | 36 | ||
37 | edit.target(match_expr.syntax().text_range()); | 37 | edit.target(match_expr.syntax().text_range()); |
38 | edit.set_cursor(expr.syntax().text_range().start()); | 38 | edit.set_cursor(expr.syntax().text_range().start()); |
@@ -63,21 +63,22 @@ fn resolve_enum_def( | |||
63 | } | 63 | } |
64 | 64 | ||
65 | fn build_pat(var: ast::EnumVariant) -> Option<ast::Pat> { | 65 | fn build_pat(var: ast::EnumVariant) -> Option<ast::Pat> { |
66 | let path = Make::<ast::Path>::from(var.parent_enum().name()?, var.name()?); | 66 | let path = make::path_qualified( |
67 | make::path_from_name_ref(make::name_ref(&var.parent_enum().name()?.syntax().to_string())), | ||
68 | make::name_ref(&var.name()?.syntax().to_string()), | ||
69 | ); | ||
67 | 70 | ||
68 | let pat: ast::Pat = match var.kind() { | 71 | let pat: ast::Pat = match var.kind() { |
69 | ast::StructKind::Tuple(field_list) => { | 72 | ast::StructKind::Tuple(field_list) => { |
70 | let pats = iter::repeat(Make::<ast::PlaceholderPat>::placeholder().into()) | 73 | let pats = |
71 | .take(field_list.fields().count()); | 74 | iter::repeat(make::placeholder_pat().into()).take(field_list.fields().count()); |
72 | Make::<ast::TupleStructPat>::from(path, pats).into() | 75 | make::tuple_struct_pat(path, pats).into() |
73 | } | 76 | } |
74 | ast::StructKind::Named(field_list) => { | 77 | ast::StructKind::Named(field_list) => { |
75 | let pats = field_list | 78 | let pats = field_list.fields().map(|f| make::bind_pat(f.name().unwrap()).into()); |
76 | .fields() | 79 | make::record_pat(path, pats).into() |
77 | .map(|f| Make::<ast::BindPat>::from_name(f.name().unwrap()).into()); | ||
78 | Make::<ast::RecordPat>::from(path, pats).into() | ||
79 | } | 80 | } |
80 | ast::StructKind::Unit => Make::<ast::PathPat>::from_path(path).into(), | 81 | ast::StructKind::Unit => make::path_pat(path).into(), |
81 | }; | 82 | }; |
82 | 83 | ||
83 | Some(pat) | 84 | Some(pat) |
diff --git a/crates/ra_assists/src/assists/move_bounds.rs b/crates/ra_assists/src/assists/move_bounds.rs index 671826013..fd4bdc55c 100644 --- a/crates/ra_assists/src/assists/move_bounds.rs +++ b/crates/ra_assists/src/assists/move_bounds.rs | |||
@@ -1,11 +1,11 @@ | |||
1 | use hir::db::HirDatabase; | 1 | use hir::db::HirDatabase; |
2 | use ra_syntax::{ | 2 | use ra_syntax::{ |
3 | ast::{self, AstNode, NameOwner, TypeBoundsOwner}, | 3 | ast::{self, make, AstNode, NameOwner, TypeBoundsOwner}, |
4 | SyntaxElement, | 4 | SyntaxElement, |
5 | SyntaxKind::*, | 5 | SyntaxKind::*, |
6 | }; | 6 | }; |
7 | 7 | ||
8 | use crate::{ast_builder::Make, ast_editor::AstEditor, Assist, AssistCtx, AssistId}; | 8 | use crate::{ast_editor::AstEditor, Assist, AssistCtx, AssistId}; |
9 | 9 | ||
10 | pub(crate) fn move_bounds_to_where_clause(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { | 10 | pub(crate) fn move_bounds_to_where_clause(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { |
11 | let type_param_list = ctx.node_at_offset::<ast::TypeParamList>()?; | 11 | let type_param_list = ctx.node_at_offset::<ast::TypeParamList>()?; |
@@ -50,7 +50,7 @@ pub(crate) fn move_bounds_to_where_clause(mut ctx: AssistCtx<impl HirDatabase>) | |||
50 | 50 | ||
51 | let where_clause = { | 51 | let where_clause = { |
52 | let predicates = type_param_list.type_params().filter_map(build_predicate); | 52 | let predicates = type_param_list.type_params().filter_map(build_predicate); |
53 | Make::<ast::WhereClause>::from_predicates(predicates) | 53 | make::where_clause(predicates) |
54 | }; | 54 | }; |
55 | 55 | ||
56 | let to_insert = match anchor.prev_sibling_or_token() { | 56 | let to_insert = match anchor.prev_sibling_or_token() { |
@@ -68,8 +68,8 @@ pub(crate) fn move_bounds_to_where_clause(mut ctx: AssistCtx<impl HirDatabase>) | |||
68 | } | 68 | } |
69 | 69 | ||
70 | fn build_predicate(param: ast::TypeParam) -> Option<ast::WherePred> { | 70 | fn build_predicate(param: ast::TypeParam) -> Option<ast::WherePred> { |
71 | let path = Make::<ast::Path>::from_name(param.name()?); | 71 | let path = make::path_from_name_ref(make::name_ref(¶m.name()?.syntax().to_string())); |
72 | let predicate = Make::<ast::WherePred>::from(path, param.type_bound_list()?.bounds()); | 72 | let predicate = make::where_pred(path, param.type_bound_list()?.bounds()); |
73 | Some(predicate) | 73 | Some(predicate) |
74 | } | 74 | } |
75 | 75 | ||