aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/ast/edit.rs
diff options
context:
space:
mode:
authorDmitry <[email protected]>2020-08-09 14:35:51 +0100
committerDmitry <[email protected]>2020-08-09 14:39:32 +0100
commit8068302fefc75440b823f4bf1731a5f347d7c767 (patch)
tree251b967182e79bc82a58c2fb208c688f6152df1f /crates/ra_syntax/src/ast/edit.rs
parent1a43a0f63e0008787225abb6fb2baef97b6a39e0 (diff)
parent8a57afe5a4bfab40072a83f7dc4ca560bf860919 (diff)
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'crates/ra_syntax/src/ast/edit.rs')
-rw-r--r--crates/ra_syntax/src/ast/edit.rs51
1 files changed, 29 insertions, 22 deletions
diff --git a/crates/ra_syntax/src/ast/edit.rs b/crates/ra_syntax/src/ast/edit.rs
index abc7a646c..5ed123f91 100644
--- a/crates/ra_syntax/src/ast/edit.rs
+++ b/crates/ra_syntax/src/ast/edit.rs
@@ -29,9 +29,9 @@ impl ast::BinExpr {
29 } 29 }
30} 30}
31 31
32impl ast::FnDef { 32impl ast::Fn {
33 #[must_use] 33 #[must_use]
34 pub fn with_body(&self, body: ast::BlockExpr) -> ast::FnDef { 34 pub fn with_body(&self, body: ast::BlockExpr) -> ast::Fn {
35 let mut to_insert: ArrayVec<[SyntaxElement; 2]> = ArrayVec::new(); 35 let mut to_insert: ArrayVec<[SyntaxElement; 2]> = ArrayVec::new();
36 let old_body_or_semi: SyntaxElement = if let Some(old_body) = self.body() { 36 let old_body_or_semi: SyntaxElement = if let Some(old_body) = self.body() {
37 old_body.syntax().clone().into() 37 old_body.syntax().clone().into()
@@ -80,9 +80,12 @@ where
80 } 80 }
81} 81}
82 82
83impl ast::ItemList { 83impl ast::AssocItemList {
84 #[must_use] 84 #[must_use]
85 pub fn append_items(&self, items: impl IntoIterator<Item = ast::AssocItem>) -> ast::ItemList { 85 pub fn append_items(
86 &self,
87 items: impl IntoIterator<Item = ast::AssocItem>,
88 ) -> ast::AssocItemList {
86 let mut res = self.clone(); 89 let mut res = self.clone();
87 if !self.syntax().text().contains_char('\n') { 90 if !self.syntax().text().contains_char('\n') {
88 res = make_multiline(res); 91 res = make_multiline(res);
@@ -92,7 +95,7 @@ impl ast::ItemList {
92 } 95 }
93 96
94 #[must_use] 97 #[must_use]
95 pub fn append_item(&self, item: ast::AssocItem) -> ast::ItemList { 98 pub fn append_item(&self, item: ast::AssocItem) -> ast::AssocItemList {
96 let (indent, position) = match self.assoc_items().last() { 99 let (indent, position) = match self.assoc_items().last() {
97 Some(it) => ( 100 Some(it) => (
98 leading_indent(it.syntax()).unwrap_or_default().to_string(), 101 leading_indent(it.syntax()).unwrap_or_default().to_string(),
@@ -113,18 +116,18 @@ impl ast::ItemList {
113 } 116 }
114} 117}
115 118
116impl ast::RecordFieldList { 119impl ast::RecordExprFieldList {
117 #[must_use] 120 #[must_use]
118 pub fn append_field(&self, field: &ast::RecordField) -> ast::RecordFieldList { 121 pub fn append_field(&self, field: &ast::RecordExprField) -> ast::RecordExprFieldList {
119 self.insert_field(InsertPosition::Last, field) 122 self.insert_field(InsertPosition::Last, field)
120 } 123 }
121 124
122 #[must_use] 125 #[must_use]
123 pub fn insert_field( 126 pub fn insert_field(
124 &self, 127 &self,
125 position: InsertPosition<&'_ ast::RecordField>, 128 position: InsertPosition<&'_ ast::RecordExprField>,
126 field: &ast::RecordField, 129 field: &ast::RecordExprField,
127 ) -> ast::RecordFieldList { 130 ) -> ast::RecordExprFieldList {
128 let is_multiline = self.syntax().text().contains_char('\n'); 131 let is_multiline = self.syntax().text().contains_char('\n');
129 let ws; 132 let ws;
130 let space = if is_multiline { 133 let space = if is_multiline {
@@ -189,9 +192,9 @@ impl ast::RecordFieldList {
189 } 192 }
190} 193}
191 194
192impl ast::TypeAliasDef { 195impl ast::TypeAlias {
193 #[must_use] 196 #[must_use]
194 pub fn remove_bounds(&self) -> ast::TypeAliasDef { 197 pub fn remove_bounds(&self) -> ast::TypeAlias {
195 let colon = match self.colon_token() { 198 let colon = match self.colon_token() {
196 Some(it) => it, 199 Some(it) => it,
197 None => return self.clone(), 200 None => return self.clone(),
@@ -234,17 +237,17 @@ impl ast::Path {
234 237
235impl ast::PathSegment { 238impl ast::PathSegment {
236 #[must_use] 239 #[must_use]
237 pub fn with_type_args(&self, type_args: ast::TypeArgList) -> ast::PathSegment { 240 pub fn with_type_args(&self, type_args: ast::GenericArgList) -> ast::PathSegment {
238 self._with_type_args(type_args, false) 241 self._with_type_args(type_args, false)
239 } 242 }
240 243
241 #[must_use] 244 #[must_use]
242 pub fn with_turbo_fish(&self, type_args: ast::TypeArgList) -> ast::PathSegment { 245 pub fn with_turbo_fish(&self, type_args: ast::GenericArgList) -> ast::PathSegment {
243 self._with_type_args(type_args, true) 246 self._with_type_args(type_args, true)
244 } 247 }
245 248
246 fn _with_type_args(&self, type_args: ast::TypeArgList, turbo: bool) -> ast::PathSegment { 249 fn _with_type_args(&self, type_args: ast::GenericArgList, turbo: bool) -> ast::PathSegment {
247 if let Some(old) = self.type_arg_list() { 250 if let Some(old) = self.generic_arg_list() {
248 return self.replace_children( 251 return self.replace_children(
249 single_node(old.syntax().clone()), 252 single_node(old.syntax().clone()),
250 iter::once(type_args.syntax().clone().into()), 253 iter::once(type_args.syntax().clone().into()),
@@ -259,9 +262,9 @@ impl ast::PathSegment {
259 } 262 }
260} 263}
261 264
262impl ast::UseItem { 265impl ast::Use {
263 #[must_use] 266 #[must_use]
264 pub fn with_use_tree(&self, use_tree: ast::UseTree) -> ast::UseItem { 267 pub fn with_use_tree(&self, use_tree: ast::UseTree) -> ast::Use {
265 if let Some(old) = self.use_tree() { 268 if let Some(old) = self.use_tree() {
266 return self.replace_descendant(old, use_tree); 269 return self.replace_descendant(old, use_tree);
267 } 270 }
@@ -314,8 +317,12 @@ impl ast::UseTree {
314 Some(it) => it, 317 Some(it) => it,
315 None => return self.clone(), 318 None => return self.clone(),
316 }; 319 };
317 let use_tree = 320 let use_tree = make::use_tree(
318 make::use_tree(suffix, self.use_tree_list(), self.alias(), self.star_token().is_some()); 321 suffix,
322 self.use_tree_list(),
323 self.rename(),
324 self.star_token().is_some(),
325 );
319 let nested = make::use_tree_list(iter::once(use_tree)); 326 let nested = make::use_tree_list(iter::once(use_tree));
320 return make::use_tree(prefix.clone(), Some(nested), None, false); 327 return make::use_tree(prefix.clone(), Some(nested), None, false);
321 328
@@ -383,7 +390,7 @@ impl ast::MatchArmList {
383 #[must_use] 390 #[must_use]
384 pub fn remove_placeholder(&self) -> ast::MatchArmList { 391 pub fn remove_placeholder(&self) -> ast::MatchArmList {
385 let placeholder = 392 let placeholder =
386 self.arms().find(|arm| matches!(arm.pat(), Some(ast::Pat::PlaceholderPat(_)))); 393 self.arms().find(|arm| matches!(arm.pat(), Some(ast::Pat::WildcardPat(_))));
387 if let Some(placeholder) = placeholder { 394 if let Some(placeholder) = placeholder {
388 self.remove_arm(&placeholder) 395 self.remove_arm(&placeholder)
389 } else { 396 } else {
@@ -614,7 +621,7 @@ fn single_node(element: impl Into<SyntaxElement>) -> RangeInclusive<SyntaxElemen
614#[test] 621#[test]
615fn test_increase_indent() { 622fn test_increase_indent() {
616 let arm_list = { 623 let arm_list = {
617 let arm = make::match_arm(iter::once(make::placeholder_pat().into()), make::expr_unit()); 624 let arm = make::match_arm(iter::once(make::wildcard_pat().into()), make::expr_unit());
618 make::match_arm_list(vec![arm.clone(), arm]) 625 make::match_arm_list(vec![arm.clone(), arm])
619 }; 626 };
620 assert_eq!( 627 assert_eq!(