aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/ast/edit.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax/src/ast/edit.rs')
-rw-r--r--crates/ra_syntax/src/ast/edit.rs42
1 files changed, 42 insertions, 0 deletions
diff --git a/crates/ra_syntax/src/ast/edit.rs b/crates/ra_syntax/src/ast/edit.rs
index d88a0cf4b..0e78d8b63 100644
--- a/crates/ra_syntax/src/ast/edit.rs
+++ b/crates/ra_syntax/src/ast/edit.rs
@@ -207,6 +207,48 @@ impl ast::TypeParam {
207 } 207 }
208} 208}
209 209
210impl ast::Path {
211 #[must_use]
212 pub fn with_segment(&self, segment: ast::PathSegment) -> ast::Path {
213 if let Some(old) = self.segment() {
214 return replace_children(
215 self,
216 single_node(old.syntax().clone()),
217 iter::once(segment.syntax().clone().into()),
218 );
219 }
220 self.clone()
221 }
222}
223
224impl ast::PathSegment {
225 #[must_use]
226 pub fn with_type_args(&self, type_args: ast::TypeArgList) -> ast::PathSegment {
227 self._with_type_args(type_args, false)
228 }
229
230 #[must_use]
231 pub fn with_turbo_fish(&self, type_args: ast::TypeArgList) -> ast::PathSegment {
232 self._with_type_args(type_args, true)
233 }
234
235 fn _with_type_args(&self, type_args: ast::TypeArgList, turbo: bool) -> ast::PathSegment {
236 if let Some(old) = self.type_arg_list() {
237 return replace_children(
238 self,
239 single_node(old.syntax().clone()),
240 iter::once(type_args.syntax().clone().into()),
241 );
242 }
243 let mut to_insert: ArrayVec<[SyntaxElement; 2]> = ArrayVec::new();
244 if turbo {
245 to_insert.push(make::token(T![::]).into());
246 }
247 to_insert.push(type_args.syntax().clone().into());
248 insert_children(self, InsertPosition::Last, to_insert)
249 }
250}
251
210#[must_use] 252#[must_use]
211pub fn strip_attrs_and_docs<N: ast::AttrsOwner>(node: &N) -> N { 253pub fn strip_attrs_and_docs<N: ast::AttrsOwner>(node: &N) -> N {
212 N::cast(strip_attrs_and_docs_inner(node.syntax().clone())).unwrap() 254 N::cast(strip_attrs_and_docs_inner(node.syntax().clone())).unwrap()