aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/ast/edit.rs
diff options
context:
space:
mode:
authorLuca Barbieri <[email protected]>2020-04-03 20:12:09 +0100
committerAleksey Kladov <[email protected]>2020-04-09 10:50:37 +0100
commit60f4d7bd8c0ecb9f23557464e824140a2be8f41a (patch)
tree00aea343b133272e1df072bd7c839fddf07f36f6 /crates/ra_syntax/src/ast/edit.rs
parent85956932872481cf4813c5e7794d981a9edb4623 (diff)
Provide more complete AST accessors to support usage in rustc
Diffstat (limited to 'crates/ra_syntax/src/ast/edit.rs')
-rw-r--r--crates/ra_syntax/src/ast/edit.rs26
1 files changed, 11 insertions, 15 deletions
diff --git a/crates/ra_syntax/src/ast/edit.rs b/crates/ra_syntax/src/ast/edit.rs
index b69cae234..d79310995 100644
--- a/crates/ra_syntax/src/ast/edit.rs
+++ b/crates/ra_syntax/src/ast/edit.rs
@@ -99,7 +99,7 @@ impl ast::ItemList {
99 None => match self.l_curly() { 99 None => match self.l_curly() {
100 Some(it) => ( 100 Some(it) => (
101 " ".to_string() + &leading_indent(self.syntax()).unwrap_or_default(), 101 " ".to_string() + &leading_indent(self.syntax()).unwrap_or_default(),
102 InsertPosition::After(it), 102 InsertPosition::After(it.syntax().clone().into()),
103 ), 103 ),
104 None => return self.clone(), 104 None => return self.clone(),
105 }, 105 },
@@ -109,10 +109,6 @@ impl ast::ItemList {
109 [ws.ws().into(), item.syntax().clone().into()].into(); 109 [ws.ws().into(), item.syntax().clone().into()].into();
110 self.insert_children(position, to_insert) 110 self.insert_children(position, to_insert)
111 } 111 }
112
113 fn l_curly(&self) -> Option<SyntaxElement> {
114 self.syntax().children_with_tokens().find(|it| it.kind() == T!['{'])
115 }
116} 112}
117 113
118impl ast::RecordFieldList { 114impl ast::RecordFieldList {
@@ -147,7 +143,7 @@ impl ast::RecordFieldList {
147 macro_rules! after_l_curly { 143 macro_rules! after_l_curly {
148 () => {{ 144 () => {{
149 let anchor = match self.l_curly() { 145 let anchor = match self.l_curly() {
150 Some(it) => it, 146 Some(it) => it.syntax().clone().into(),
151 None => return self.clone(), 147 None => return self.clone(),
152 }; 148 };
153 InsertPosition::After(anchor) 149 InsertPosition::After(anchor)
@@ -189,24 +185,20 @@ impl ast::RecordFieldList {
189 185
190 self.insert_children(position, to_insert) 186 self.insert_children(position, to_insert)
191 } 187 }
192
193 fn l_curly(&self) -> Option<SyntaxElement> {
194 self.syntax().children_with_tokens().find(|it| it.kind() == T!['{'])
195 }
196} 188}
197 189
198impl ast::TypeParam { 190impl ast::TypeParam {
199 #[must_use] 191 #[must_use]
200 pub fn remove_bounds(&self) -> ast::TypeParam { 192 pub fn remove_bounds(&self) -> ast::TypeParam {
201 let colon = match self.colon_token() { 193 let colon = match self.colon() {
202 Some(it) => it, 194 Some(it) => it,
203 None => return self.clone(), 195 None => return self.clone(),
204 }; 196 };
205 let end = match self.type_bound_list() { 197 let end = match self.type_bound_list() {
206 Some(it) => it.syntax().clone().into(), 198 Some(it) => it.syntax().clone().into(),
207 None => colon.clone().into(), 199 None => colon.syntax().clone().into(),
208 }; 200 };
209 self.replace_children(colon.into()..=end, iter::empty()) 201 self.replace_children(colon.syntax().clone().into()..=end, iter::empty())
210 } 202 }
211} 203}
212 204
@@ -305,8 +297,12 @@ impl ast::UseTree {
305 Some(it) => it, 297 Some(it) => it,
306 None => return self.clone(), 298 None => return self.clone(),
307 }; 299 };
308 let use_tree = 300 let use_tree = make::use_tree(
309 make::use_tree(suffix.clone(), self.use_tree_list(), self.alias(), self.has_star()); 301 suffix.clone(),
302 self.use_tree_list(),
303 self.alias(),
304 self.star().is_some(),
305 );
310 let nested = make::use_tree_list(iter::once(use_tree)); 306 let nested = make::use_tree_list(iter::once(use_tree));
311 return make::use_tree(prefix.clone(), Some(nested), None, false); 307 return make::use_tree(prefix.clone(), Some(nested), None, false);
312 308