diff options
author | Aleksey Kladov <[email protected]> | 2020-03-18 15:41:24 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-03-18 18:34:47 +0000 |
commit | 3f6dc20d3cf3fa101552a9067b98a1314260a679 (patch) | |
tree | 7be0684f1c2660eb5da089d1067d13a343e8bcff /crates/ra_syntax/src/ast/edit.rs | |
parent | 4e50efcfc5fc6e280e638dd446b90e970f7ce699 (diff) |
Merge imports assist
Work towards #2220
Diffstat (limited to 'crates/ra_syntax/src/ast/edit.rs')
-rw-r--r-- | crates/ra_syntax/src/ast/edit.rs | 20 |
1 files changed, 20 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] |