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

@ -639,6 +639,7 @@ fn enum_variants_with_paths(
ImportPathConfig {
prefer_no_std: ctx.config.prefer_no_std,
prefer_prelude: ctx.config.prefer_prelude,
prefer_absolute: ctx.config.prefer_absolute,
},
) {
// Variants with trivial paths are already added by the existing completion logic,

View file

@ -177,6 +177,7 @@ pub(crate) fn complete_expr_path(
ImportPathConfig {
prefer_no_std: ctx.config.prefer_no_std,
prefer_prelude: ctx.config.prefer_prelude,
prefer_absolute: ctx.config.prefer_absolute,
},
)
.filter(|it| it.len() > 1);
@ -202,6 +203,7 @@ pub(crate) fn complete_expr_path(
ImportPathConfig {
prefer_no_std: ctx.config.prefer_no_std,
prefer_prelude: ctx.config.prefer_prelude,
prefer_absolute: ctx.config.prefer_absolute,
},
)
.filter(|it| it.len() > 1);

View file

@ -259,6 +259,7 @@ fn import_on_the_fly(
let import_cfg = ImportPathConfig {
prefer_no_std: ctx.config.prefer_no_std,
prefer_prelude: ctx.config.prefer_prelude,
prefer_absolute: ctx.config.prefer_absolute,
};
import_assets
@ -309,6 +310,7 @@ fn import_on_the_fly_pat_(
let cfg = ImportPathConfig {
prefer_no_std: ctx.config.prefer_no_std,
prefer_prelude: ctx.config.prefer_prelude,
prefer_absolute: ctx.config.prefer_absolute,
};
import_assets
@ -354,6 +356,7 @@ fn import_on_the_fly_method(
let cfg = ImportPathConfig {
prefer_no_std: ctx.config.prefer_no_std,
prefer_prelude: ctx.config.prefer_prelude,
prefer_absolute: ctx.config.prefer_absolute,
};
import_assets

View file

@ -63,6 +63,7 @@ pub(crate) fn complete_postfix(
let cfg = ImportPathConfig {
prefer_no_std: ctx.config.prefer_no_std,
prefer_prelude: ctx.config.prefer_prelude,
prefer_absolute: ctx.config.prefer_absolute,
};
if let Some(drop_trait) = ctx.famous_defs().core_ops_Drop() {

View file

@ -22,6 +22,7 @@ pub struct CompletionConfig {
pub insert_use: InsertUseConfig,
pub prefer_no_std: bool,
pub prefer_prelude: bool,
pub prefer_absolute: bool,
pub snippets: Vec<Snippet>,
pub limit: Option<usize>,
}

View file

@ -253,6 +253,7 @@ pub fn resolve_completion_edits(
let cfg = ImportPathConfig {
prefer_no_std: config.prefer_no_std,
prefer_prelude: config.prefer_prelude,
prefer_absolute: config.prefer_absolute,
};
imports.into_iter().for_each(|(full_import_path, imported_name)| {

View file

@ -298,6 +298,7 @@ pub(crate) fn render_expr(
let cfg = ImportPathConfig {
prefer_no_std: ctx.config.prefer_no_std,
prefer_prelude: ctx.config.prefer_prelude,
prefer_absolute: ctx.config.prefer_absolute,
};
let label = expr.gen_source_code(&ctx.scope, &mut label_formatter, cfg).ok()?;

View file

@ -172,6 +172,7 @@ fn import_edits(ctx: &CompletionContext<'_>, requires: &[GreenNode]) -> Option<V
let import_cfg = ImportPathConfig {
prefer_no_std: ctx.config.prefer_no_std,
prefer_prelude: ctx.config.prefer_prelude,
prefer_absolute: ctx.config.prefer_absolute,
};
let resolve = |import: &GreenNode| {

View file

@ -79,6 +79,7 @@ pub(crate) const TEST_CONFIG: CompletionConfig = CompletionConfig {
},
prefer_no_std: false,
prefer_prelude: true,
prefer_absolute: false,
snippets: Vec::new(),
limit: None,
};

View file

@ -870,6 +870,38 @@ fn main() {
);
}
#[test]
fn config_prefer_absolute() {
let fixture = r#"
//- /lib.rs crate:dep
pub mod foo {
pub mod bar {
pub struct Item;
}
}
//- /main.rs crate:main deps:dep
use ::dep::foo::bar;
fn main() {
Ite$0
}"#;
let mut config = TEST_CONFIG;
config.prefer_absolute = true;
check_edit_with_config(
config.clone(),
"Item",
fixture,
r#"
use ::dep::foo::bar::{self, Item};
fn main() {
Item
}"#,
);
}
#[test]
fn unresolved_qualifier() {
let fixture = r#"