aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/ast/edit.rs
diff options
context:
space:
mode:
authorZac Pullar-Strecker <[email protected]>2020-07-31 03:12:44 +0100
committerZac Pullar-Strecker <[email protected]>2020-07-31 03:12:44 +0100
commitf05d7b41a719d848844b054a16477b29d0f063c6 (patch)
tree0a8a0946e8aef2ce64d4c13d0035ba41cce2daf3 /crates/ra_syntax/src/ast/edit.rs
parent73ff610e41959e3e7c78a2b4b25b086883132956 (diff)
parent6b7cb8b5ab539fc4333ce34bc29bf77c976f232a (diff)
Merge remote-tracking branch 'upstream/master' into 503-hover-doc-links
Hasn't fixed tests yet.
Diffstat (limited to 'crates/ra_syntax/src/ast/edit.rs')
-rw-r--r--crates/ra_syntax/src/ast/edit.rs46
1 files changed, 32 insertions, 14 deletions
diff --git a/crates/ra_syntax/src/ast/edit.rs b/crates/ra_syntax/src/ast/edit.rs
index 2ef173a03..8d3e42f25 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,6 +192,21 @@ impl ast::RecordFieldList {
189 } 192 }
190} 193}
191 194
195impl ast::TypeAlias {
196 #[must_use]
197 pub fn remove_bounds(&self) -> ast::TypeAlias {
198 let colon = match self.colon_token() {
199 Some(it) => it,
200 None => return self.clone(),
201 };
202 let end = match self.type_bound_list() {
203 Some(it) => it.syntax().clone().into(),
204 None => colon.clone().into(),
205 };
206 self.replace_children(colon.into()..=end, iter::empty())
207 }
208}
209
192impl ast::TypeParam { 210impl ast::TypeParam {
193 #[must_use] 211 #[must_use]
194 pub fn remove_bounds(&self) -> ast::TypeParam { 212 pub fn remove_bounds(&self) -> ast::TypeParam {
@@ -244,9 +262,9 @@ impl ast::PathSegment {
244 } 262 }
245} 263}
246 264
247impl ast::UseItem { 265impl ast::Use {
248 #[must_use] 266 #[must_use]
249 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 {
250 if let Some(old) = self.use_tree() { 268 if let Some(old) = self.use_tree() {
251 return self.replace_descendant(old, use_tree); 269 return self.replace_descendant(old, use_tree);
252 } 270 }
@@ -300,9 +318,9 @@ impl ast::UseTree {
300 None => return self.clone(), 318 None => return self.clone(),
301 }; 319 };
302 let use_tree = make::use_tree( 320 let use_tree = make::use_tree(
303 suffix.clone(), 321 suffix,
304 self.use_tree_list(), 322 self.use_tree_list(),
305 self.alias(), 323 self.rename(),
306 self.star_token().is_some(), 324 self.star_token().is_some(),
307 ); 325 );
308 let nested = make::use_tree_list(iter::once(use_tree)); 326 let nested = make::use_tree_list(iter::once(use_tree));