Merge #10589
10589: Fix: expand into {} if the glob import is unused r=lnicola a=rainy-me close #10524 I think the second `expand into {}` behavior is genuinely better. (maybe this should been labeled with good first issue xd) Co-authored-by: rainy-me <github@yue.coffee>
This commit is contained in:
commit
5051717856
@ -72,7 +72,7 @@ pub(crate) fn expand_glob_import(acc: &mut Assists, ctx: &AssistContext) -> Opti
|
|||||||
|
|
||||||
match use_tree.star_token() {
|
match use_tree.star_token() {
|
||||||
Some(star) => {
|
Some(star) => {
|
||||||
let needs_braces = use_tree.path().is_some() && names_to_import.len() > 1;
|
let needs_braces = use_tree.path().is_some() && names_to_import.len() != 1;
|
||||||
if needs_braces {
|
if needs_braces {
|
||||||
ted::replace(star, expanded.syntax())
|
ted::replace(star, expanded.syntax())
|
||||||
} else {
|
} else {
|
||||||
@ -294,6 +294,39 @@ fn qux(bar: Bar, baz: Baz) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn expanding_glob_import_unused() {
|
||||||
|
check_assist(
|
||||||
|
expand_glob_import,
|
||||||
|
r"
|
||||||
|
mod foo {
|
||||||
|
pub struct Bar;
|
||||||
|
pub struct Baz;
|
||||||
|
pub struct Qux;
|
||||||
|
|
||||||
|
pub fn f() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
use foo::*$0;
|
||||||
|
|
||||||
|
fn qux() {}
|
||||||
|
",
|
||||||
|
r"
|
||||||
|
mod foo {
|
||||||
|
pub struct Bar;
|
||||||
|
pub struct Baz;
|
||||||
|
pub struct Qux;
|
||||||
|
|
||||||
|
pub fn f() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
use foo::{};
|
||||||
|
|
||||||
|
fn qux() {}
|
||||||
|
",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn expanding_glob_import_with_existing_explicit_names() {
|
fn expanding_glob_import_with_existing_explicit_names() {
|
||||||
check_assist(
|
check_assist(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user