diff options
author | Jonas Schievink <[email protected]> | 2020-07-14 12:33:37 +0100 |
---|---|---|
committer | Jonas Schievink <[email protected]> | 2020-07-14 12:33:37 +0100 |
commit | 85f5cbc9dc7027f922198f6c2d06cf382aad6970 (patch) | |
tree | fd73b03c195602955cd71af8d3d8a49007f94009 | |
parent | 0f654b06ab093e7bb057cfd68b27925803b003d8 (diff) |
Move remove_bounds to edit.rs
-rw-r--r-- | crates/ra_assists/src/handlers/add_missing_impl_members.rs | 10 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/edit.rs | 15 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/make.rs | 13 |
3 files changed, 16 insertions, 22 deletions
diff --git a/crates/ra_assists/src/handlers/add_missing_impl_members.rs b/crates/ra_assists/src/handlers/add_missing_impl_members.rs index 124cead6c..f185e61e5 100644 --- a/crates/ra_assists/src/handlers/add_missing_impl_members.rs +++ b/crates/ra_assists/src/handlers/add_missing_impl_members.rs | |||
@@ -159,7 +159,7 @@ fn add_missing_impl_members_inner( | |||
159 | .map(|it| match it { | 159 | .map(|it| match it { |
160 | ast::AssocItem::FnDef(def) => ast::AssocItem::FnDef(add_body(def)), | 160 | ast::AssocItem::FnDef(def) => ast::AssocItem::FnDef(add_body(def)), |
161 | ast::AssocItem::TypeAliasDef(def) => { | 161 | ast::AssocItem::TypeAliasDef(def) => { |
162 | ast::AssocItem::TypeAliasDef(remove_bounds(def)) | 162 | ast::AssocItem::TypeAliasDef(def.remove_bounds()) |
163 | } | 163 | } |
164 | _ => it, | 164 | _ => it, |
165 | }) | 165 | }) |
@@ -191,14 +191,6 @@ fn add_missing_impl_members_inner( | |||
191 | }) | 191 | }) |
192 | } | 192 | } |
193 | 193 | ||
194 | fn remove_bounds(ty_def: ast::TypeAliasDef) -> ast::TypeAliasDef { | ||
195 | if let Some(name) = ty_def.name() { | ||
196 | make::type_alias_def(name, None, ty_def.type_ref()) | ||
197 | } else { | ||
198 | ty_def | ||
199 | } | ||
200 | } | ||
201 | |||
202 | fn add_body(fn_def: ast::FnDef) -> ast::FnDef { | 194 | fn add_body(fn_def: ast::FnDef) -> ast::FnDef { |
203 | if fn_def.body().is_some() { | 195 | if fn_def.body().is_some() { |
204 | return fn_def; | 196 | return fn_def; |
diff --git a/crates/ra_syntax/src/ast/edit.rs b/crates/ra_syntax/src/ast/edit.rs index 940c30c7f..abc7a646c 100644 --- a/crates/ra_syntax/src/ast/edit.rs +++ b/crates/ra_syntax/src/ast/edit.rs | |||
@@ -189,6 +189,21 @@ impl ast::RecordFieldList { | |||
189 | } | 189 | } |
190 | } | 190 | } |
191 | 191 | ||
192 | impl ast::TypeAliasDef { | ||
193 | #[must_use] | ||
194 | pub fn remove_bounds(&self) -> ast::TypeAliasDef { | ||
195 | let colon = match self.colon_token() { | ||
196 | Some(it) => it, | ||
197 | None => return self.clone(), | ||
198 | }; | ||
199 | let end = match self.type_bound_list() { | ||
200 | Some(it) => it.syntax().clone().into(), | ||
201 | None => colon.clone().into(), | ||
202 | }; | ||
203 | self.replace_children(colon.into()..=end, iter::empty()) | ||
204 | } | ||
205 | } | ||
206 | |||
192 | impl ast::TypeParam { | 207 | impl ast::TypeParam { |
193 | #[must_use] | 208 | #[must_use] |
194 | pub fn remove_bounds(&self) -> ast::TypeParam { | 209 | pub fn remove_bounds(&self) -> ast::TypeParam { |
diff --git a/crates/ra_syntax/src/ast/make.rs b/crates/ra_syntax/src/ast/make.rs index 42116afbb..192c610f1 100644 --- a/crates/ra_syntax/src/ast/make.rs +++ b/crates/ra_syntax/src/ast/make.rs | |||
@@ -64,19 +64,6 @@ pub fn use_item(use_tree: ast::UseTree) -> ast::UseItem { | |||
64 | ast_from_text(&format!("use {};", use_tree)) | 64 | ast_from_text(&format!("use {};", use_tree)) |
65 | } | 65 | } |
66 | 66 | ||
67 | pub fn type_alias_def( | ||
68 | name: ast::Name, | ||
69 | bounds: Option<ast::TypeBoundList>, | ||
70 | ty: Option<ast::TypeRef>, | ||
71 | ) -> ast::TypeAliasDef { | ||
72 | match (bounds, ty) { | ||
73 | (None, None) => ast_from_text(&format!("type {};", name)), | ||
74 | (None, Some(ty)) => ast_from_text(&format!("type {} = {};", name, ty)), | ||
75 | (Some(bounds), None) => ast_from_text(&format!("type {}: {};", name, bounds)), | ||
76 | (Some(bounds), Some(ty)) => ast_from_text(&format!("type {}: {} = {};", name, bounds, ty)), | ||
77 | } | ||
78 | } | ||
79 | |||
80 | pub fn record_field(name: ast::NameRef, expr: Option<ast::Expr>) -> ast::RecordField { | 67 | pub fn record_field(name: ast::NameRef, expr: Option<ast::Expr>) -> ast::RecordField { |
81 | return match expr { | 68 | return match expr { |
82 | Some(expr) => from_text(&format!("{}: {}", name, expr)), | 69 | Some(expr) => from_text(&format!("{}: {}", name, expr)), |