diff options
Diffstat (limited to 'crates/ra_syntax/src/ast')
-rw-r--r-- | crates/ra_syntax/src/ast/edit.rs | 20 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/extensions.rs | 14 |
2 files changed, 34 insertions, 0 deletions
diff --git a/crates/ra_syntax/src/ast/edit.rs b/crates/ra_syntax/src/ast/edit.rs index 1e34db5ae..68dae008f 100644 --- a/crates/ra_syntax/src/ast/edit.rs +++ b/crates/ra_syntax/src/ast/edit.rs | |||
@@ -273,6 +273,26 @@ impl ast::UseTree { | |||
273 | } | 273 | } |
274 | self.clone() | 274 | self.clone() |
275 | } | 275 | } |
276 | |||
277 | #[must_use] | ||
278 | pub fn split_prefix(&self, prefix: &ast::Path) -> ast::UseTree { | ||
279 | let suffix = match split_path_prefix(&prefix) { | ||
280 | Some(it) => it, | ||
281 | None => return self.clone(), | ||
282 | }; | ||
283 | let use_tree = make::use_tree(suffix.clone(), self.use_tree_list(), self.alias()); | ||
284 | let nested = make::use_tree_list(iter::once(use_tree)); | ||
285 | return make::use_tree(prefix.clone(), Some(nested), None); | ||
286 | |||
287 | fn split_path_prefix(prefix: &ast::Path) -> Option<ast::Path> { | ||
288 | let parent = prefix.parent_path()?; | ||
289 | let mut res = make::path_unqualified(parent.segment()?); | ||
290 | for p in iter::successors(parent.parent_path(), |it| it.parent_path()) { | ||
291 | res = make::path_qualified(res, p.segment()?); | ||
292 | } | ||
293 | Some(res) | ||
294 | } | ||
295 | } | ||
276 | } | 296 | } |
277 | 297 | ||
278 | #[must_use] | 298 | #[must_use] |
diff --git a/crates/ra_syntax/src/ast/extensions.rs b/crates/ra_syntax/src/ast/extensions.rs index d5986e8b4..c3ae8f90e 100644 --- a/crates/ra_syntax/src/ast/extensions.rs +++ b/crates/ra_syntax/src/ast/extensions.rs | |||
@@ -167,6 +167,20 @@ impl ast::UseTreeList { | |||
167 | .and_then(ast::UseTree::cast) | 167 | .and_then(ast::UseTree::cast) |
168 | .expect("UseTreeLists are always nested in UseTrees") | 168 | .expect("UseTreeLists are always nested in UseTrees") |
169 | } | 169 | } |
170 | pub fn l_curly(&self) -> Option<SyntaxToken> { | ||
171 | self.token(T!['{']) | ||
172 | } | ||
173 | |||
174 | pub fn r_curly(&self) -> Option<SyntaxToken> { | ||
175 | self.token(T!['}']) | ||
176 | } | ||
177 | |||
178 | fn token(&self, kind: SyntaxKind) -> Option<SyntaxToken> { | ||
179 | self.syntax() | ||
180 | .children_with_tokens() | ||
181 | .filter_map(|it| it.into_token()) | ||
182 | .find(|it| it.kind() == kind) | ||
183 | } | ||
170 | } | 184 | } |
171 | 185 | ||
172 | impl ast::ImplDef { | 186 | impl ast::ImplDef { |