mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-10 15:14:32 +00:00
squash.
This commit is contained in:
parent
1b283db47f
commit
3725ab3146
43 changed files with 233 additions and 11 deletions
|
@ -183,6 +183,8 @@ fn find_path_for_module(
|
|||
let kind = if name_already_occupied_in_type_ns {
|
||||
cov_mark::hit!(ambiguous_crate_start);
|
||||
PathKind::Abs
|
||||
} else if ctx.cfg.prefer_absolute {
|
||||
PathKind::Abs
|
||||
} else {
|
||||
PathKind::Plain
|
||||
};
|
||||
|
@ -564,7 +566,13 @@ mod tests {
|
|||
/// item the `path` refers to returns that same path when called from the
|
||||
/// module the cursor is in.
|
||||
#[track_caller]
|
||||
fn check_found_path_(ra_fixture: &str, path: &str, prefer_prelude: bool, expect: Expect) {
|
||||
fn check_found_path_(
|
||||
ra_fixture: &str,
|
||||
path: &str,
|
||||
prefer_prelude: bool,
|
||||
prefer_absolute: bool,
|
||||
expect: Expect,
|
||||
) {
|
||||
let (db, pos) = TestDB::with_position(ra_fixture);
|
||||
let module = db.module_at_position(pos);
|
||||
let parsed_path_file =
|
||||
|
@ -604,7 +612,7 @@ mod tests {
|
|||
module,
|
||||
prefix,
|
||||
ignore_local_imports,
|
||||
ImportPathConfig { prefer_no_std: false, prefer_prelude },
|
||||
ImportPathConfig { prefer_no_std: false, prefer_prelude, prefer_absolute },
|
||||
);
|
||||
format_to!(
|
||||
res,
|
||||
|
@ -619,11 +627,15 @@ mod tests {
|
|||
}
|
||||
|
||||
fn check_found_path(ra_fixture: &str, path: &str, expect: Expect) {
|
||||
check_found_path_(ra_fixture, path, false, expect);
|
||||
check_found_path_(ra_fixture, path, false, false, expect);
|
||||
}
|
||||
|
||||
fn check_found_path_prelude(ra_fixture: &str, path: &str, expect: Expect) {
|
||||
check_found_path_(ra_fixture, path, true, expect);
|
||||
check_found_path_(ra_fixture, path, true, false, expect);
|
||||
}
|
||||
|
||||
fn check_found_path_absolute(ra_fixture: &str, path: &str, expect: Expect) {
|
||||
check_found_path_(ra_fixture, path, false, true, expect);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -870,6 +882,39 @@ pub mod ast {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn partially_imported_with_prefer_absolute() {
|
||||
cov_mark::check!(partially_imported);
|
||||
// Similar to partially_imported test case above, but with prefer_absolute enabled.
|
||||
// Even if the actual imported item is in external crate, if the path to that item
|
||||
// is starting from the imported name, then the path should not start from "::".
|
||||
// i.e. The first line in the expected output should not start from "::".
|
||||
check_found_path_absolute(
|
||||
r#"
|
||||
//- /main.rs crate:main deps:syntax
|
||||
|
||||
use syntax::ast;
|
||||
$0
|
||||
|
||||
//- /lib.rs crate:syntax
|
||||
pub mod ast {
|
||||
pub enum ModuleItem {
|
||||
A, B, C,
|
||||
}
|
||||
}
|
||||
"#,
|
||||
"syntax::ast::ModuleItem",
|
||||
expect![[r#"
|
||||
Plain (imports ✔): ast::ModuleItem
|
||||
Plain (imports ✖): ::syntax::ast::ModuleItem
|
||||
ByCrate(imports ✔): crate::ast::ModuleItem
|
||||
ByCrate(imports ✖): ::syntax::ast::ModuleItem
|
||||
BySelf (imports ✔): self::ast::ModuleItem
|
||||
BySelf (imports ✖): ::syntax::ast::ModuleItem
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn same_crate_reexport() {
|
||||
check_found_path(
|
||||
|
@ -1769,6 +1814,43 @@ pub mod foo {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn respects_absolute_setting() {
|
||||
let ra_fixture = r#"
|
||||
//- /main.rs crate:main deps:krate
|
||||
$0
|
||||
//- /krate.rs crate:krate
|
||||
pub mod foo {
|
||||
pub struct Foo;
|
||||
}
|
||||
"#;
|
||||
check_found_path(
|
||||
ra_fixture,
|
||||
"krate::foo::Foo",
|
||||
expect![[r#"
|
||||
Plain (imports ✔): krate::foo::Foo
|
||||
Plain (imports ✖): krate::foo::Foo
|
||||
ByCrate(imports ✔): krate::foo::Foo
|
||||
ByCrate(imports ✖): krate::foo::Foo
|
||||
BySelf (imports ✔): krate::foo::Foo
|
||||
BySelf (imports ✖): krate::foo::Foo
|
||||
"#]],
|
||||
);
|
||||
|
||||
check_found_path_absolute(
|
||||
ra_fixture,
|
||||
"krate::foo::Foo",
|
||||
expect![[r#"
|
||||
Plain (imports ✔): ::krate::foo::Foo
|
||||
Plain (imports ✖): ::krate::foo::Foo
|
||||
ByCrate(imports ✔): ::krate::foo::Foo
|
||||
ByCrate(imports ✖): ::krate::foo::Foo
|
||||
BySelf (imports ✔): ::krate::foo::Foo
|
||||
BySelf (imports ✖): ::krate::foo::Foo
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn respect_segment_length() {
|
||||
check_found_path(
|
||||
|
|
|
@ -116,6 +116,8 @@ pub struct ImportPathConfig {
|
|||
pub prefer_no_std: bool,
|
||||
/// If true, prefer import paths containing a prelude module.
|
||||
pub prefer_prelude: bool,
|
||||
/// If true, prefer abs path (starting with `::`) where it is available.
|
||||
pub prefer_absolute: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
|
@ -1043,7 +1043,11 @@ impl HirDisplay for Ty {
|
|||
module_id,
|
||||
PrefixKind::Plain,
|
||||
false,
|
||||
ImportPathConfig { prefer_no_std: false, prefer_prelude: true },
|
||||
ImportPathConfig {
|
||||
prefer_no_std: false,
|
||||
prefer_prelude: true,
|
||||
prefer_absolute: false,
|
||||
},
|
||||
) {
|
||||
write!(f, "{}", path.display(f.db.upcast()))?;
|
||||
} else {
|
||||
|
|
|
@ -15,6 +15,7 @@ pub struct AssistConfig {
|
|||
pub insert_use: InsertUseConfig,
|
||||
pub prefer_no_std: bool,
|
||||
pub prefer_prelude: bool,
|
||||
pub prefer_absolute: bool,
|
||||
pub assist_emit_must_use: bool,
|
||||
pub term_search_fuel: u64,
|
||||
pub term_search_borrowck: bool,
|
||||
|
|
|
@ -74,6 +74,7 @@ pub(crate) fn add_missing_match_arms(acc: &mut Assists, ctx: &AssistContext<'_>)
|
|||
let cfg = ImportPathConfig {
|
||||
prefer_no_std: ctx.config.prefer_no_std,
|
||||
prefer_prelude: ctx.config.prefer_prelude,
|
||||
prefer_absolute: ctx.config.prefer_absolute,
|
||||
};
|
||||
|
||||
let module = ctx.sema.scope(expr.syntax())?.module();
|
||||
|
|
|
@ -93,6 +93,7 @@ pub(crate) fn auto_import(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<
|
|||
let cfg = ImportPathConfig {
|
||||
prefer_no_std: ctx.config.prefer_no_std,
|
||||
prefer_prelude: ctx.config.prefer_prelude,
|
||||
prefer_absolute: ctx.config.prefer_absolute,
|
||||
};
|
||||
|
||||
let (import_assets, syntax_under_caret) = find_importable_node(ctx)?;
|
||||
|
|
|
@ -340,6 +340,7 @@ fn augment_references_with_imports(
|
|||
let cfg = ImportPathConfig {
|
||||
prefer_no_std: ctx.config.prefer_no_std,
|
||||
prefer_prelude: ctx.config.prefer_prelude,
|
||||
prefer_absolute: ctx.config.prefer_absolute,
|
||||
};
|
||||
|
||||
references
|
||||
|
|
|
@ -47,6 +47,7 @@ pub(crate) fn convert_into_to_from(acc: &mut Assists, ctx: &AssistContext<'_>) -
|
|||
let cfg = ImportPathConfig {
|
||||
prefer_no_std: ctx.config.prefer_no_std,
|
||||
prefer_prelude: ctx.config.prefer_prelude,
|
||||
prefer_absolute: ctx.config.prefer_absolute,
|
||||
};
|
||||
|
||||
let src_type_path = {
|
||||
|
|
|
@ -186,6 +186,7 @@ fn augment_references_with_imports(
|
|||
let cfg = ImportPathConfig {
|
||||
prefer_no_std: ctx.config.prefer_no_std,
|
||||
prefer_prelude: ctx.config.prefer_prelude,
|
||||
prefer_absolute: ctx.config.prefer_absolute,
|
||||
};
|
||||
|
||||
references
|
||||
|
|
|
@ -90,6 +90,7 @@ fn collect_data(ident_pat: ast::IdentPat, ctx: &AssistContext<'_>) -> Option<Str
|
|||
let cfg = ImportPathConfig {
|
||||
prefer_no_std: ctx.config.prefer_no_std,
|
||||
prefer_prelude: ctx.config.prefer_prelude,
|
||||
prefer_absolute: ctx.config.prefer_absolute,
|
||||
};
|
||||
|
||||
let module = ctx.sema.scope(ident_pat.syntax())?.module();
|
||||
|
|
|
@ -216,6 +216,7 @@ pub(crate) fn extract_function(acc: &mut Assists, ctx: &AssistContext<'_>) -> Op
|
|||
ImportPathConfig {
|
||||
prefer_no_std: ctx.config.prefer_no_std,
|
||||
prefer_prelude: ctx.config.prefer_prelude,
|
||||
prefer_absolute: ctx.config.prefer_absolute,
|
||||
},
|
||||
);
|
||||
|
||||
|
|
|
@ -393,6 +393,7 @@ fn process_references(
|
|||
ImportPathConfig {
|
||||
prefer_no_std: ctx.config.prefer_no_std,
|
||||
prefer_prelude: ctx.config.prefer_prelude,
|
||||
prefer_absolute: ctx.config.prefer_absolute,
|
||||
},
|
||||
);
|
||||
if let Some(mut mod_path) = mod_path {
|
||||
|
|
|
@ -64,6 +64,7 @@ fn generate_record_deref(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<(
|
|||
ImportPathConfig {
|
||||
prefer_no_std: ctx.config.prefer_no_std,
|
||||
prefer_prelude: ctx.config.prefer_prelude,
|
||||
prefer_absolute: ctx.config.prefer_absolute,
|
||||
},
|
||||
)?;
|
||||
|
||||
|
@ -111,6 +112,7 @@ fn generate_tuple_deref(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()
|
|||
ImportPathConfig {
|
||||
prefer_no_std: ctx.config.prefer_no_std,
|
||||
prefer_prelude: ctx.config.prefer_prelude,
|
||||
prefer_absolute: ctx.config.prefer_absolute,
|
||||
},
|
||||
)?;
|
||||
|
||||
|
|
|
@ -65,6 +65,7 @@ pub(crate) fn generate_new(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option
|
|||
ImportPathConfig {
|
||||
prefer_no_std: ctx.config.prefer_no_std,
|
||||
prefer_prelude: ctx.config.prefer_prelude,
|
||||
prefer_absolute: ctx.config.prefer_absolute,
|
||||
},
|
||||
)?;
|
||||
|
||||
|
|
|
@ -53,6 +53,7 @@ pub(crate) fn qualify_method_call(acc: &mut Assists, ctx: &AssistContext<'_>) ->
|
|||
ImportPathConfig {
|
||||
prefer_no_std: ctx.config.prefer_no_std,
|
||||
prefer_prelude: ctx.config.prefer_prelude,
|
||||
prefer_absolute: ctx.config.prefer_absolute,
|
||||
},
|
||||
)?;
|
||||
|
||||
|
|
|
@ -40,6 +40,7 @@ pub(crate) fn qualify_path(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option
|
|||
let cfg = ImportPathConfig {
|
||||
prefer_no_std: ctx.config.prefer_no_std,
|
||||
prefer_prelude: ctx.config.prefer_prelude,
|
||||
prefer_absolute: ctx.config.prefer_absolute,
|
||||
};
|
||||
|
||||
let mut proposed_imports: Vec<_> =
|
||||
|
|
|
@ -89,6 +89,7 @@ pub(crate) fn replace_derive_with_manual_impl(
|
|||
ImportPathConfig {
|
||||
prefer_no_std: ctx.config.prefer_no_std,
|
||||
prefer_prelude: ctx.config.prefer_prelude,
|
||||
prefer_absolute: ctx.config.prefer_absolute,
|
||||
},
|
||||
)
|
||||
.as_ref()
|
||||
|
|
|
@ -70,6 +70,7 @@ pub(crate) fn replace_qualified_name_with_use(
|
|||
ImportPathConfig {
|
||||
prefer_no_std: ctx.config.prefer_no_std,
|
||||
prefer_prelude: ctx.config.prefer_prelude,
|
||||
prefer_absolute: ctx.config.prefer_absolute,
|
||||
},
|
||||
)
|
||||
})
|
||||
|
|
|
@ -60,6 +60,7 @@ pub(crate) fn term_search(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<
|
|||
ImportPathConfig {
|
||||
prefer_no_std: ctx.config.prefer_no_std,
|
||||
prefer_prelude: ctx.config.prefer_prelude,
|
||||
prefer_absolute: ctx.config.prefer_absolute,
|
||||
},
|
||||
)
|
||||
.ok()
|
||||
|
|
|
@ -142,6 +142,7 @@ pub(crate) fn desugar_async_into_impl_future(
|
|||
ImportPathConfig {
|
||||
prefer_no_std: ctx.config.prefer_no_std,
|
||||
prefer_prelude: ctx.config.prefer_prelude,
|
||||
prefer_absolute: ctx.config.prefer_absolute,
|
||||
},
|
||||
)?;
|
||||
let trait_path = trait_path.display(ctx.db());
|
||||
|
|
|
@ -30,6 +30,7 @@ pub(crate) const TEST_CONFIG: AssistConfig = AssistConfig {
|
|||
},
|
||||
prefer_no_std: false,
|
||||
prefer_prelude: true,
|
||||
prefer_absolute: false,
|
||||
assist_emit_must_use: false,
|
||||
term_search_fuel: 400,
|
||||
term_search_borrowck: true,
|
||||
|
@ -47,6 +48,7 @@ pub(crate) const TEST_CONFIG_NO_SNIPPET_CAP: AssistConfig = AssistConfig {
|
|||
},
|
||||
prefer_no_std: false,
|
||||
prefer_prelude: true,
|
||||
prefer_absolute: false,
|
||||
assist_emit_must_use: false,
|
||||
term_search_fuel: 400,
|
||||
term_search_borrowck: true,
|
||||
|
@ -64,6 +66,7 @@ pub(crate) const TEST_CONFIG_IMPORT_ONE: AssistConfig = AssistConfig {
|
|||
},
|
||||
prefer_no_std: false,
|
||||
prefer_prelude: true,
|
||||
prefer_absolute: false,
|
||||
assist_emit_must_use: false,
|
||||
term_search_fuel: 400,
|
||||
term_search_borrowck: true,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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>,
|
||||
}
|
||||
|
|
|
@ -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)| {
|
||||
|
|
|
@ -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()?;
|
||||
|
|
|
@ -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| {
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
|
|
|
@ -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#"
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -146,6 +146,7 @@ pub(crate) fn json_in_items(
|
|||
let cfg = ImportPathConfig {
|
||||
prefer_no_std: config.prefer_no_std,
|
||||
prefer_prelude: config.prefer_prelude,
|
||||
prefer_absolute: config.prefer_absolute,
|
||||
};
|
||||
|
||||
if !scope_has("Serialize") {
|
||||
|
|
|
@ -128,6 +128,7 @@ fn fixes(ctx: &DiagnosticsContext<'_>, d: &hir::MissingFields) -> Option<Vec<Ass
|
|||
ImportPathConfig {
|
||||
prefer_no_std: ctx.config.prefer_no_std,
|
||||
prefer_prelude: ctx.config.prefer_prelude,
|
||||
prefer_absolute: ctx.config.prefer_absolute,
|
||||
},
|
||||
)?;
|
||||
|
||||
|
|
|
@ -67,6 +67,7 @@ fn fixes(ctx: &DiagnosticsContext<'_>, d: &hir::TypedHole) -> Option<Vec<Assist>
|
|||
ImportPathConfig {
|
||||
prefer_no_std: ctx.config.prefer_no_std,
|
||||
prefer_prelude: ctx.config.prefer_prelude,
|
||||
prefer_absolute: ctx.config.prefer_absolute,
|
||||
},
|
||||
)
|
||||
.ok()
|
||||
|
|
|
@ -231,6 +231,7 @@ pub struct DiagnosticsConfig {
|
|||
pub insert_use: InsertUseConfig,
|
||||
pub prefer_no_std: bool,
|
||||
pub prefer_prelude: bool,
|
||||
pub prefer_absolute: bool,
|
||||
pub term_search_fuel: u64,
|
||||
pub term_search_borrowck: bool,
|
||||
}
|
||||
|
@ -258,6 +259,7 @@ impl DiagnosticsConfig {
|
|||
},
|
||||
prefer_no_std: false,
|
||||
prefer_prelude: true,
|
||||
prefer_absolute: false,
|
||||
term_search_fuel: 400,
|
||||
term_search_borrowck: true,
|
||||
}
|
||||
|
|
|
@ -663,7 +663,11 @@ impl Match {
|
|||
.module();
|
||||
for (path, resolved_path) in &template.resolved_paths {
|
||||
if let hir::PathResolution::Def(module_def) = resolved_path.resolution {
|
||||
let cfg = ImportPathConfig { prefer_no_std: false, prefer_prelude: true };
|
||||
let cfg = ImportPathConfig {
|
||||
prefer_no_std: false,
|
||||
prefer_prelude: true,
|
||||
prefer_absolute: false,
|
||||
};
|
||||
let mod_path = module.find_path(sema.db, module_def, cfg).ok_or_else(|| {
|
||||
match_error!("Failed to render template path `{}` at match location")
|
||||
})?;
|
||||
|
|
|
@ -443,7 +443,11 @@ impl flags::AnalysisStats {
|
|||
.gen_source_code(
|
||||
&scope,
|
||||
&mut formatter,
|
||||
ImportPathConfig { prefer_no_std: false, prefer_prelude: true },
|
||||
ImportPathConfig {
|
||||
prefer_no_std: false,
|
||||
prefer_prelude: true,
|
||||
prefer_absolute: false,
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
syntax_hit_found |= trim(&original_text) == trim(&generated);
|
||||
|
@ -992,6 +996,7 @@ impl flags::AnalysisStats {
|
|||
},
|
||||
prefer_no_std: false,
|
||||
prefer_prelude: true,
|
||||
prefer_absolute: false,
|
||||
style_lints: false,
|
||||
term_search_fuel: 400,
|
||||
term_search_borrowck: true,
|
||||
|
|
|
@ -359,6 +359,8 @@ config_data! {
|
|||
imports_preferPrelude: bool = false,
|
||||
/// The path structure for newly inserted paths to use.
|
||||
imports_prefix: ImportPrefixDef = ImportPrefixDef::Plain,
|
||||
/// Whether to prefix external (including std, core) crate imports with `::`. e.g. "use ::std::io::Read;".
|
||||
imports_prefixExternPrelude: bool = false,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1280,6 +1282,7 @@ impl Config {
|
|||
prefer_no_std: self.imports_preferNoStd(source_root).to_owned(),
|
||||
assist_emit_must_use: self.assist_emitMustUse(source_root).to_owned(),
|
||||
prefer_prelude: self.imports_preferPrelude(source_root).to_owned(),
|
||||
prefer_absolute: self.imports_prefixExternPrelude(source_root).to_owned(),
|
||||
term_search_fuel: self.assist_termSearch_fuel(source_root).to_owned() as u64,
|
||||
term_search_borrowck: self.assist_termSearch_borrowcheck(source_root).to_owned(),
|
||||
}
|
||||
|
@ -1311,6 +1314,7 @@ impl Config {
|
|||
insert_use: self.insert_use_config(source_root),
|
||||
prefer_no_std: self.imports_preferNoStd(source_root).to_owned(),
|
||||
prefer_prelude: self.imports_preferPrelude(source_root).to_owned(),
|
||||
prefer_absolute: self.imports_prefixExternPrelude(source_root).to_owned(),
|
||||
snippets: self.snippets.clone().to_vec(),
|
||||
limit: self.completion_limit().to_owned(),
|
||||
enable_term_search: self.completion_termSearch_enable().to_owned(),
|
||||
|
@ -1339,6 +1343,7 @@ impl Config {
|
|||
insert_use: self.insert_use_config(source_root),
|
||||
prefer_no_std: self.imports_preferNoStd(source_root).to_owned(),
|
||||
prefer_prelude: self.imports_preferPrelude(source_root).to_owned(),
|
||||
prefer_absolute: self.imports_prefixExternPrelude(source_root).to_owned(),
|
||||
style_lints: self.diagnostics_styleLints_enable().to_owned(),
|
||||
term_search_fuel: self.assist_termSearch_fuel(source_root).to_owned() as u64,
|
||||
term_search_borrowck: self.assist_termSearch_borrowcheck(source_root).to_owned(),
|
||||
|
|
|
@ -152,6 +152,7 @@ fn integrated_completion_benchmark() {
|
|||
},
|
||||
prefer_no_std: false,
|
||||
prefer_prelude: true,
|
||||
prefer_absolute: false,
|
||||
snippets: Vec::new(),
|
||||
limit: None,
|
||||
};
|
||||
|
@ -197,6 +198,7 @@ fn integrated_completion_benchmark() {
|
|||
},
|
||||
prefer_no_std: false,
|
||||
prefer_prelude: true,
|
||||
prefer_absolute: false,
|
||||
snippets: Vec::new(),
|
||||
limit: None,
|
||||
};
|
||||
|
@ -240,6 +242,7 @@ fn integrated_completion_benchmark() {
|
|||
},
|
||||
prefer_no_std: false,
|
||||
prefer_prelude: true,
|
||||
prefer_absolute: false,
|
||||
snippets: Vec::new(),
|
||||
limit: None,
|
||||
};
|
||||
|
@ -299,6 +302,7 @@ fn integrated_diagnostics_benchmark() {
|
|||
},
|
||||
prefer_no_std: false,
|
||||
prefer_prelude: false,
|
||||
prefer_absolute: false,
|
||||
term_search_fuel: 400,
|
||||
term_search_borrowck: true,
|
||||
};
|
||||
|
|
|
@ -594,6 +594,11 @@ Whether to prefer import paths containing a `prelude` module.
|
|||
--
|
||||
The path structure for newly inserted paths to use.
|
||||
--
|
||||
[[rust-analyzer.imports.prefixExternPrelude]]rust-analyzer.imports.prefixExternPrelude (default: `false`)::
|
||||
+
|
||||
--
|
||||
Whether to prefix external (including std, core) crate imports with `::`. e.g. "use ::std::io::Read;".
|
||||
--
|
||||
[[rust-analyzer.inlayHints.bindingModeHints.enable]]rust-analyzer.inlayHints.bindingModeHints.enable (default: `false`)::
|
||||
+
|
||||
--
|
||||
|
|
|
@ -1732,6 +1732,16 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"title": "imports",
|
||||
"properties": {
|
||||
"rust-analyzer.imports.prefixExternPrelude": {
|
||||
"markdownDescription": "Whether to prefix external (including std, core) crate imports with `::`. e.g. \"use ::std::io::Read;\".",
|
||||
"default": false,
|
||||
"type": "boolean"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"title": "inlayHints",
|
||||
"properties": {
|
||||
|
|
Loading…
Reference in a new issue