mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 04:53:34 +00:00
**Merge Imports** assist handles self
This commit is contained in:
parent
d583f2c46d
commit
0635458a6b
3 changed files with 38 additions and 3 deletions
|
@ -164,6 +164,33 @@ use std::fmt::{Display, Debug};
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn merge_self1() {
|
||||||
|
check_assist(
|
||||||
|
merge_imports,
|
||||||
|
r"
|
||||||
|
use std::fmt<|>;
|
||||||
|
use std::fmt::Display;
|
||||||
|
",
|
||||||
|
r"
|
||||||
|
use std::fmt::{self, Display};
|
||||||
|
",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn merge_self2() {
|
||||||
|
check_assist(
|
||||||
|
merge_imports,
|
||||||
|
r"
|
||||||
|
use std::{fmt, <|>fmt::Display};
|
||||||
|
",
|
||||||
|
r"
|
||||||
|
use std::{fmt::{Display, self}};
|
||||||
|
",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_merge_nested() {
|
fn test_merge_nested() {
|
||||||
check_assist(
|
check_assist(
|
||||||
|
|
|
@ -313,10 +313,15 @@ impl ast::UseTree {
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn split_prefix(&self, prefix: &ast::Path) -> ast::UseTree {
|
pub fn split_prefix(&self, prefix: &ast::Path) -> ast::UseTree {
|
||||||
let suffix = match split_path_prefix(&prefix) {
|
let suffix = if self.path().as_ref() == Some(prefix) && self.use_tree_list().is_none() {
|
||||||
|
make::path_unqualified(make::path_segment_self())
|
||||||
|
} else {
|
||||||
|
match split_path_prefix(&prefix) {
|
||||||
Some(it) => it,
|
Some(it) => it,
|
||||||
None => return self.clone(),
|
None => return self.clone(),
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let use_tree = make::use_tree(
|
let use_tree = make::use_tree(
|
||||||
suffix,
|
suffix,
|
||||||
self.use_tree_list(),
|
self.use_tree_list(),
|
||||||
|
|
|
@ -24,6 +24,9 @@ pub fn ty(text: &str) -> ast::Type {
|
||||||
pub fn path_segment(name_ref: ast::NameRef) -> ast::PathSegment {
|
pub fn path_segment(name_ref: ast::NameRef) -> ast::PathSegment {
|
||||||
ast_from_text(&format!("use {};", name_ref))
|
ast_from_text(&format!("use {};", name_ref))
|
||||||
}
|
}
|
||||||
|
pub fn path_segment_self() -> ast::PathSegment {
|
||||||
|
ast_from_text("use self;")
|
||||||
|
}
|
||||||
pub fn path_unqualified(segment: ast::PathSegment) -> ast::Path {
|
pub fn path_unqualified(segment: ast::PathSegment) -> ast::Path {
|
||||||
path_from_text(&format!("use {}", segment))
|
path_from_text(&format!("use {}", segment))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue