diff options
author | Benjamin Coenen <[email protected]> | 2020-04-09 17:37:34 +0100 |
---|---|---|
committer | Benjamin Coenen <[email protected]> | 2020-04-09 18:12:50 +0100 |
commit | c1317d692321ba5ba8f138067ebefbb9559d098d (patch) | |
tree | e29a44577e4d2cf55b6f53e3428abea43bbd33d7 /crates/ra_syntax/src/ast/edit.rs | |
parent | fc70cf9458c5234decafdd52b9aced790ac43d7a (diff) | |
parent | 30f0ad159a0f260f54356385de63c171722adb72 (diff) |
feat: add support for feature attributes in struct literal
Signed-off-by: Benjamin Coenen <[email protected]>
Diffstat (limited to 'crates/ra_syntax/src/ast/edit.rs')
-rw-r--r-- | crates/ra_syntax/src/ast/edit.rs | 26 |
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 | ||
118 | impl ast::RecordFieldList { | 114 | impl 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 | ||
198 | impl ast::TypeParam { | 190 | impl 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 | ||