Auto merge of #17523 - wada314:master, r=Veykril

Add an option to use "::" for the external crate prefix.

Fixes #11823 .
Hi I'm very new to rust-analyzer and not sure how the review process are. Can somebody take a look at this PR? thanks!
This commit is contained in:
bors 2024-07-07 08:32:46 +00:00
commit a494aaba87
43 changed files with 233 additions and 11 deletions

View file

@ -1222,6 +1222,26 @@ use self::foo::{self, Bar, Foo};
);
}
#[test]
fn insert_with_double_colon_prefixed_import_merge() {
check_with_config(
"use ::ext::foo::Foo",
r#"
use ::ext::foo::Foo as _;
"#,
r#"
use ::ext::foo::Foo;
"#,
&InsertUseConfig {
granularity: ImportGranularity::Crate,
prefix_kind: hir::PrefixKind::BySelf,
enforce_granularity: true,
group: true,
skip_glob_imports: true,
},
);
}
fn check_with_config(
path: &str,
ra_fixture_before: &str,

View file

@ -308,8 +308,11 @@ impl Ctx<'_> {
parent.segment()?.name_ref()?,
)
.and_then(|trait_ref| {
let cfg =
ImportPathConfig { prefer_no_std: false, prefer_prelude: true };
let cfg = ImportPathConfig {
prefer_no_std: false,
prefer_prelude: true,
prefer_absolute: false,
};
let found_path = self.target_module.find_path(
self.source_scope.db.upcast(),
hir::ModuleDef::Trait(trait_ref),
@ -348,7 +351,11 @@ impl Ctx<'_> {
}
}
let cfg = ImportPathConfig { prefer_no_std: false, prefer_prelude: true };
let cfg = ImportPathConfig {
prefer_no_std: false,
prefer_prelude: true,
prefer_absolute: false,
};
let found_path =
self.target_module.find_path(self.source_scope.db.upcast(), def, cfg)?;
let res = mod_path_to_ast(&found_path).clone_for_update();
@ -383,7 +390,11 @@ impl Ctx<'_> {
if let Some(adt) = ty.as_adt() {
if let ast::Type::PathType(path_ty) = &ast_ty {
let cfg = ImportPathConfig { prefer_no_std: false, prefer_prelude: true };
let cfg = ImportPathConfig {
prefer_no_std: false,
prefer_prelude: true,
prefer_absolute: false,
};
let found_path = self.target_module.find_path(
self.source_scope.db.upcast(),
ModuleDef::from(adt),