diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-08-12 17:59:40 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-08-12 17:59:40 +0100 |
commit | f277ec27ac024992e8b8834c68e16b31c983be1b (patch) | |
tree | e754396302c88aa602bb77be30ce1835c205f730 /crates/syntax/src | |
parent | d583f2c46d22cf8d643ebf98be9cb7059a304431 (diff) | |
parent | 0635458a6bf883b5abcae024afb17a11688fef92 (diff) |
Merge #5730
5730: **Merge Imports** assist handles self
r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/syntax/src')
-rw-r--r-- | crates/syntax/src/ast/edit.rs | 11 | ||||
-rw-r--r-- | crates/syntax/src/ast/make.rs | 3 |
2 files changed, 11 insertions, 3 deletions
diff --git a/crates/syntax/src/ast/edit.rs b/crates/syntax/src/ast/edit.rs index 5ed123f91..2667d9af4 100644 --- a/crates/syntax/src/ast/edit.rs +++ b/crates/syntax/src/ast/edit.rs | |||
@@ -313,10 +313,15 @@ impl ast::UseTree { | |||
313 | 313 | ||
314 | #[must_use] | 314 | #[must_use] |
315 | pub fn split_prefix(&self, prefix: &ast::Path) -> ast::UseTree { | 315 | pub fn split_prefix(&self, prefix: &ast::Path) -> ast::UseTree { |
316 | let suffix = match split_path_prefix(&prefix) { | 316 | let suffix = if self.path().as_ref() == Some(prefix) && self.use_tree_list().is_none() { |
317 | Some(it) => it, | 317 | make::path_unqualified(make::path_segment_self()) |
318 | None => return self.clone(), | 318 | } else { |
319 | match split_path_prefix(&prefix) { | ||
320 | Some(it) => it, | ||
321 | None => return self.clone(), | ||
322 | } | ||
319 | }; | 323 | }; |
324 | |||
320 | let use_tree = make::use_tree( | 325 | let use_tree = make::use_tree( |
321 | suffix, | 326 | suffix, |
322 | self.use_tree_list(), | 327 | self.use_tree_list(), |
diff --git a/crates/syntax/src/ast/make.rs b/crates/syntax/src/ast/make.rs index 254a37fe3..3009faed7 100644 --- a/crates/syntax/src/ast/make.rs +++ b/crates/syntax/src/ast/make.rs | |||
@@ -24,6 +24,9 @@ pub fn ty(text: &str) -> ast::Type { | |||
24 | pub fn path_segment(name_ref: ast::NameRef) -> ast::PathSegment { | 24 | pub fn path_segment(name_ref: ast::NameRef) -> ast::PathSegment { |
25 | ast_from_text(&format!("use {};", name_ref)) | 25 | ast_from_text(&format!("use {};", name_ref)) |
26 | } | 26 | } |
27 | pub fn path_segment_self() -> ast::PathSegment { | ||
28 | ast_from_text("use self;") | ||
29 | } | ||
27 | pub fn path_unqualified(segment: ast::PathSegment) -> ast::Path { | 30 | pub fn path_unqualified(segment: ast::PathSegment) -> ast::Path { |
28 | path_from_text(&format!("use {}", segment)) | 31 | path_from_text(&format!("use {}", segment)) |
29 | } | 32 | } |