mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
internal: refactor prefer_no_std
/prefer_prelude
bools into a struct
This commit is contained in:
parent
6a16749eb0
commit
b75301cec8
37 changed files with 304 additions and 351 deletions
|
@ -17,7 +17,7 @@ use crate::{
|
||||||
nameres::DefMap,
|
nameres::DefMap,
|
||||||
path::{ModPath, PathKind},
|
path::{ModPath, PathKind},
|
||||||
visibility::{Visibility, VisibilityExplicitness},
|
visibility::{Visibility, VisibilityExplicitness},
|
||||||
ModuleDefId, ModuleId,
|
ImportPathConfig, ModuleDefId, ModuleId,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Find a path that can be used to refer to a certain item. This can depend on
|
/// Find a path that can be used to refer to a certain item. This can depend on
|
||||||
|
@ -28,21 +28,10 @@ pub fn find_path(
|
||||||
from: ModuleId,
|
from: ModuleId,
|
||||||
prefix_kind: PrefixKind,
|
prefix_kind: PrefixKind,
|
||||||
ignore_local_imports: bool,
|
ignore_local_imports: bool,
|
||||||
prefer_no_std: bool,
|
cfg: ImportPathConfig,
|
||||||
prefer_prelude: bool,
|
|
||||||
) -> Option<ModPath> {
|
) -> Option<ModPath> {
|
||||||
let _p = tracing::span!(tracing::Level::INFO, "find_path").entered();
|
let _p = tracing::span!(tracing::Level::INFO, "find_path").entered();
|
||||||
find_path_inner(
|
find_path_inner(FindPathCtx { db, prefix: prefix_kind, cfg, ignore_local_imports }, item, from)
|
||||||
FindPathCtx {
|
|
||||||
db,
|
|
||||||
prefix: prefix_kind,
|
|
||||||
prefer_no_std,
|
|
||||||
prefer_prelude,
|
|
||||||
ignore_local_imports,
|
|
||||||
},
|
|
||||||
item,
|
|
||||||
from,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
|
@ -88,8 +77,7 @@ impl PrefixKind {
|
||||||
struct FindPathCtx<'db> {
|
struct FindPathCtx<'db> {
|
||||||
db: &'db dyn DefDatabase,
|
db: &'db dyn DefDatabase,
|
||||||
prefix: PrefixKind,
|
prefix: PrefixKind,
|
||||||
prefer_no_std: bool,
|
cfg: ImportPathConfig,
|
||||||
prefer_prelude: bool,
|
|
||||||
ignore_local_imports: bool,
|
ignore_local_imports: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,7 +95,11 @@ fn find_path_inner(ctx: FindPathCtx<'_>, item: ItemInNs, from: ModuleId) -> Opti
|
||||||
let mut visited_modules = FxHashSet::default();
|
let mut visited_modules = FxHashSet::default();
|
||||||
return find_path_for_module(
|
return find_path_for_module(
|
||||||
FindPathCtx {
|
FindPathCtx {
|
||||||
prefer_no_std: ctx.prefer_no_std || ctx.db.crate_supports_no_std(crate_root.krate),
|
cfg: ImportPathConfig {
|
||||||
|
prefer_no_std: ctx.cfg.prefer_no_std
|
||||||
|
|| ctx.db.crate_supports_no_std(crate_root.krate),
|
||||||
|
..ctx.cfg
|
||||||
|
},
|
||||||
..ctx
|
..ctx
|
||||||
},
|
},
|
||||||
&def_map,
|
&def_map,
|
||||||
|
@ -160,7 +152,11 @@ fn find_path_inner(ctx: FindPathCtx<'_>, item: ItemInNs, from: ModuleId) -> Opti
|
||||||
|
|
||||||
calculate_best_path(
|
calculate_best_path(
|
||||||
FindPathCtx {
|
FindPathCtx {
|
||||||
prefer_no_std: ctx.prefer_no_std || ctx.db.crate_supports_no_std(crate_root.krate),
|
cfg: ImportPathConfig {
|
||||||
|
prefer_no_std: ctx.cfg.prefer_no_std
|
||||||
|
|| ctx.db.crate_supports_no_std(crate_root.krate),
|
||||||
|
..ctx.cfg
|
||||||
|
},
|
||||||
..ctx
|
..ctx
|
||||||
},
|
},
|
||||||
&def_map,
|
&def_map,
|
||||||
|
@ -381,9 +377,7 @@ fn calculate_best_path(
|
||||||
path.0.push_segment(name);
|
path.0.push_segment(name);
|
||||||
|
|
||||||
let new_path = match best_path.take() {
|
let new_path = match best_path.take() {
|
||||||
Some(best_path) => {
|
Some(best_path) => select_best_path(best_path, path, ctx.cfg),
|
||||||
select_best_path(best_path, path, ctx.prefer_no_std, ctx.prefer_prelude)
|
|
||||||
}
|
|
||||||
None => path,
|
None => path,
|
||||||
};
|
};
|
||||||
best_path_len = new_path.0.len();
|
best_path_len = new_path.0.len();
|
||||||
|
@ -425,12 +419,7 @@ fn calculate_best_path(
|
||||||
);
|
);
|
||||||
|
|
||||||
let new_path_with_stab = match best_path.take() {
|
let new_path_with_stab = match best_path.take() {
|
||||||
Some(best_path) => select_best_path(
|
Some(best_path) => select_best_path(best_path, path_with_stab, ctx.cfg),
|
||||||
best_path,
|
|
||||||
path_with_stab,
|
|
||||||
ctx.prefer_no_std,
|
|
||||||
ctx.prefer_prelude,
|
|
||||||
),
|
|
||||||
None => path_with_stab,
|
None => path_with_stab,
|
||||||
};
|
};
|
||||||
update_best_path(&mut best_path, new_path_with_stab);
|
update_best_path(&mut best_path, new_path_with_stab);
|
||||||
|
@ -446,8 +435,7 @@ fn calculate_best_path(
|
||||||
fn select_best_path(
|
fn select_best_path(
|
||||||
old_path @ (_, old_stability): (ModPath, Stability),
|
old_path @ (_, old_stability): (ModPath, Stability),
|
||||||
new_path @ (_, new_stability): (ModPath, Stability),
|
new_path @ (_, new_stability): (ModPath, Stability),
|
||||||
prefer_no_std: bool,
|
cfg: ImportPathConfig,
|
||||||
prefer_prelude: bool,
|
|
||||||
) -> (ModPath, Stability) {
|
) -> (ModPath, Stability) {
|
||||||
match (old_stability, new_stability) {
|
match (old_stability, new_stability) {
|
||||||
(Stable, Unstable) => return old_path,
|
(Stable, Unstable) => return old_path,
|
||||||
|
@ -461,7 +449,7 @@ fn select_best_path(
|
||||||
let (old_path, _) = &old;
|
let (old_path, _) = &old;
|
||||||
let new_has_prelude = new_path.segments().iter().any(|seg| seg == &known::prelude);
|
let new_has_prelude = new_path.segments().iter().any(|seg| seg == &known::prelude);
|
||||||
let old_has_prelude = old_path.segments().iter().any(|seg| seg == &known::prelude);
|
let old_has_prelude = old_path.segments().iter().any(|seg| seg == &known::prelude);
|
||||||
match (new_has_prelude, old_has_prelude, prefer_prelude) {
|
match (new_has_prelude, old_has_prelude, cfg.prefer_prelude) {
|
||||||
(true, false, true) | (false, true, false) => new,
|
(true, false, true) | (false, true, false) => new,
|
||||||
(true, false, false) | (false, true, true) => old,
|
(true, false, false) | (false, true, true) => old,
|
||||||
// no prelude difference in the paths, so pick the shorter one
|
// no prelude difference in the paths, so pick the shorter one
|
||||||
|
@ -482,7 +470,7 @@ fn select_best_path(
|
||||||
|
|
||||||
match (old_path.0.segments().first(), new_path.0.segments().first()) {
|
match (old_path.0.segments().first(), new_path.0.segments().first()) {
|
||||||
(Some(old), Some(new)) if STD_CRATES.contains(old) && STD_CRATES.contains(new) => {
|
(Some(old), Some(new)) if STD_CRATES.contains(old) && STD_CRATES.contains(new) => {
|
||||||
let rank = match prefer_no_std {
|
let rank = match cfg.prefer_no_std {
|
||||||
false => |name: &Name| match name {
|
false => |name: &Name| match name {
|
||||||
name if name == &known::core => 0,
|
name if name == &known::core => 0,
|
||||||
name if name == &known::alloc => 1,
|
name if name == &known::alloc => 1,
|
||||||
|
@ -647,10 +635,9 @@ mod tests {
|
||||||
{
|
{
|
||||||
let found_path = find_path_inner(
|
let found_path = find_path_inner(
|
||||||
FindPathCtx {
|
FindPathCtx {
|
||||||
prefer_no_std: false,
|
|
||||||
db: &db,
|
db: &db,
|
||||||
prefix,
|
prefix,
|
||||||
prefer_prelude,
|
cfg: ImportPathConfig { prefer_no_std: false, prefer_prelude },
|
||||||
ignore_local_imports,
|
ignore_local_imports,
|
||||||
},
|
},
|
||||||
resolved,
|
resolved,
|
||||||
|
|
|
@ -108,6 +108,15 @@ use crate::{
|
||||||
|
|
||||||
type FxIndexMap<K, V> =
|
type FxIndexMap<K, V> =
|
||||||
indexmap::IndexMap<K, V, std::hash::BuildHasherDefault<rustc_hash::FxHasher>>;
|
indexmap::IndexMap<K, V, std::hash::BuildHasherDefault<rustc_hash::FxHasher>>;
|
||||||
|
/// A wrapper around two booleans, [`ImportPathConfig::prefer_no_std`] and [`ImportPathConfig::prefer_prelude`].
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq, Hash, Copy)]
|
||||||
|
pub struct ImportPathConfig {
|
||||||
|
/// If true, prefer to unconditionally use imports of the `core` and `alloc` crate
|
||||||
|
/// over the std.
|
||||||
|
pub prefer_no_std: bool,
|
||||||
|
/// If true, prefer import paths containing a prelude module.
|
||||||
|
pub prefer_prelude: bool,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ItemLoc<N: ItemTreeNode> {
|
pub struct ItemLoc<N: ItemTreeNode> {
|
||||||
|
|
|
@ -21,7 +21,8 @@ use hir_def::{
|
||||||
path::{Path, PathKind},
|
path::{Path, PathKind},
|
||||||
type_ref::{TraitBoundModifier, TypeBound, TypeRef},
|
type_ref::{TraitBoundModifier, TypeBound, TypeRef},
|
||||||
visibility::Visibility,
|
visibility::Visibility,
|
||||||
HasModule, ItemContainerId, LocalFieldId, Lookup, ModuleDefId, ModuleId, TraitId,
|
HasModule, ImportPathConfig, ItemContainerId, LocalFieldId, Lookup, ModuleDefId, ModuleId,
|
||||||
|
TraitId,
|
||||||
};
|
};
|
||||||
use hir_expand::name::Name;
|
use hir_expand::name::Name;
|
||||||
use intern::{Internable, Interned};
|
use intern::{Internable, Interned};
|
||||||
|
@ -1000,9 +1001,8 @@ impl HirDisplay for Ty {
|
||||||
ItemInNs::Types((*def_id).into()),
|
ItemInNs::Types((*def_id).into()),
|
||||||
module_id,
|
module_id,
|
||||||
PrefixKind::Plain,
|
PrefixKind::Plain,
|
||||||
false,
|
|
||||||
false,
|
|
||||||
true,
|
true,
|
||||||
|
ImportPathConfig { prefer_no_std: false, prefer_prelude: true },
|
||||||
) {
|
) {
|
||||||
write!(f, "{}", path.display(f.db.upcast()))?;
|
write!(f, "{}", path.display(f.db.upcast()))?;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -122,6 +122,7 @@ pub use {
|
||||||
per_ns::Namespace,
|
per_ns::Namespace,
|
||||||
type_ref::{Mutability, TypeRef},
|
type_ref::{Mutability, TypeRef},
|
||||||
visibility::Visibility,
|
visibility::Visibility,
|
||||||
|
ImportPathConfig,
|
||||||
// FIXME: This is here since some queries take it as input that are used
|
// FIXME: This is here since some queries take it as input that are used
|
||||||
// outside of hir.
|
// outside of hir.
|
||||||
{AdtId, MacroId, ModuleDefId},
|
{AdtId, MacroId, ModuleDefId},
|
||||||
|
@ -792,8 +793,7 @@ impl Module {
|
||||||
self,
|
self,
|
||||||
db: &dyn DefDatabase,
|
db: &dyn DefDatabase,
|
||||||
item: impl Into<ItemInNs>,
|
item: impl Into<ItemInNs>,
|
||||||
prefer_no_std: bool,
|
cfg: ImportPathConfig,
|
||||||
prefer_prelude: bool,
|
|
||||||
) -> Option<ModPath> {
|
) -> Option<ModPath> {
|
||||||
hir_def::find_path::find_path(
|
hir_def::find_path::find_path(
|
||||||
db,
|
db,
|
||||||
|
@ -801,8 +801,7 @@ impl Module {
|
||||||
self.into(),
|
self.into(),
|
||||||
PrefixKind::Plain,
|
PrefixKind::Plain,
|
||||||
false,
|
false,
|
||||||
prefer_no_std,
|
cfg,
|
||||||
prefer_prelude,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -813,18 +812,9 @@ impl Module {
|
||||||
db: &dyn DefDatabase,
|
db: &dyn DefDatabase,
|
||||||
item: impl Into<ItemInNs>,
|
item: impl Into<ItemInNs>,
|
||||||
prefix_kind: PrefixKind,
|
prefix_kind: PrefixKind,
|
||||||
prefer_no_std: bool,
|
cfg: ImportPathConfig,
|
||||||
prefer_prelude: bool,
|
|
||||||
) -> Option<ModPath> {
|
) -> Option<ModPath> {
|
||||||
hir_def::find_path::find_path(
|
hir_def::find_path::find_path(db, item.into().into(), self.into(), prefix_kind, true, cfg)
|
||||||
db,
|
|
||||||
item.into().into(),
|
|
||||||
self.into(),
|
|
||||||
prefix_kind,
|
|
||||||
true,
|
|
||||||
prefer_no_std,
|
|
||||||
prefer_prelude,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
//! Type tree for term search
|
//! Type tree for term search
|
||||||
|
|
||||||
|
use hir_def::ImportPathConfig;
|
||||||
use hir_expand::mod_path::ModPath;
|
use hir_expand::mod_path::ModPath;
|
||||||
use hir_ty::{
|
use hir_ty::{
|
||||||
db::HirDatabase,
|
db::HirDatabase,
|
||||||
|
@ -16,22 +17,20 @@ use crate::{
|
||||||
fn mod_item_path(
|
fn mod_item_path(
|
||||||
sema_scope: &SemanticsScope<'_>,
|
sema_scope: &SemanticsScope<'_>,
|
||||||
def: &ModuleDef,
|
def: &ModuleDef,
|
||||||
prefer_no_std: bool,
|
cfg: ImportPathConfig,
|
||||||
prefer_prelude: bool,
|
|
||||||
) -> Option<ModPath> {
|
) -> Option<ModPath> {
|
||||||
let db = sema_scope.db;
|
let db = sema_scope.db;
|
||||||
let m = sema_scope.module();
|
let m = sema_scope.module();
|
||||||
m.find_path(db.upcast(), *def, prefer_no_std, prefer_prelude)
|
m.find_path(db.upcast(), *def, cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Helper function to get path to `ModuleDef` as string
|
/// Helper function to get path to `ModuleDef` as string
|
||||||
fn mod_item_path_str(
|
fn mod_item_path_str(
|
||||||
sema_scope: &SemanticsScope<'_>,
|
sema_scope: &SemanticsScope<'_>,
|
||||||
def: &ModuleDef,
|
def: &ModuleDef,
|
||||||
prefer_no_std: bool,
|
cfg: ImportPathConfig,
|
||||||
prefer_prelude: bool,
|
|
||||||
) -> Result<String, DisplaySourceCodeError> {
|
) -> Result<String, DisplaySourceCodeError> {
|
||||||
let path = mod_item_path(sema_scope, def, prefer_no_std, prefer_prelude);
|
let path = mod_item_path(sema_scope, def, cfg);
|
||||||
path.map(|it| it.display(sema_scope.db.upcast()).to_string())
|
path.map(|it| it.display(sema_scope.db.upcast()).to_string())
|
||||||
.ok_or(DisplaySourceCodeError::PathNotFound)
|
.ok_or(DisplaySourceCodeError::PathNotFound)
|
||||||
}
|
}
|
||||||
|
@ -40,8 +39,7 @@ fn mod_item_path_str(
|
||||||
fn type_path(
|
fn type_path(
|
||||||
sema_scope: &SemanticsScope<'_>,
|
sema_scope: &SemanticsScope<'_>,
|
||||||
ty: &Type,
|
ty: &Type,
|
||||||
prefer_no_std: bool,
|
cfg: ImportPathConfig,
|
||||||
prefer_prelude: bool,
|
|
||||||
) -> Result<String, DisplaySourceCodeError> {
|
) -> Result<String, DisplaySourceCodeError> {
|
||||||
let db = sema_scope.db;
|
let db = sema_scope.db;
|
||||||
let m = sema_scope.module();
|
let m = sema_scope.module();
|
||||||
|
@ -50,9 +48,7 @@ fn type_path(
|
||||||
Some(adt) => {
|
Some(adt) => {
|
||||||
let ty_name = ty.display_source_code(db, m.id, true)?;
|
let ty_name = ty.display_source_code(db, m.id, true)?;
|
||||||
|
|
||||||
let mut path =
|
let mut path = mod_item_path(sema_scope, &ModuleDef::Adt(adt), cfg).unwrap();
|
||||||
mod_item_path(sema_scope, &ModuleDef::Adt(adt), prefer_no_std, prefer_prelude)
|
|
||||||
.unwrap();
|
|
||||||
path.pop_segment();
|
path.pop_segment();
|
||||||
let path = path.display(db.upcast()).to_string();
|
let path = path.display(db.upcast()).to_string();
|
||||||
let res = match path.is_empty() {
|
let res = match path.is_empty() {
|
||||||
|
@ -137,11 +133,10 @@ impl Expr {
|
||||||
&self,
|
&self,
|
||||||
sema_scope: &SemanticsScope<'_>,
|
sema_scope: &SemanticsScope<'_>,
|
||||||
many_formatter: &mut dyn FnMut(&Type) -> String,
|
many_formatter: &mut dyn FnMut(&Type) -> String,
|
||||||
prefer_no_std: bool,
|
cfg: ImportPathConfig,
|
||||||
prefer_prelude: bool,
|
|
||||||
) -> Result<String, DisplaySourceCodeError> {
|
) -> Result<String, DisplaySourceCodeError> {
|
||||||
let db = sema_scope.db;
|
let db = sema_scope.db;
|
||||||
let mod_item_path_str = |s, def| mod_item_path_str(s, def, prefer_no_std, prefer_prelude);
|
let mod_item_path_str = |s, def| mod_item_path_str(s, def, cfg);
|
||||||
match self {
|
match self {
|
||||||
Expr::Const(it) => mod_item_path_str(sema_scope, &ModuleDef::Const(*it)),
|
Expr::Const(it) => mod_item_path_str(sema_scope, &ModuleDef::Const(*it)),
|
||||||
Expr::Static(it) => mod_item_path_str(sema_scope, &ModuleDef::Static(*it)),
|
Expr::Static(it) => mod_item_path_str(sema_scope, &ModuleDef::Static(*it)),
|
||||||
|
@ -151,9 +146,7 @@ impl Expr {
|
||||||
Expr::Function { func, params, .. } => {
|
Expr::Function { func, params, .. } => {
|
||||||
let args = params
|
let args = params
|
||||||
.iter()
|
.iter()
|
||||||
.map(|f| {
|
.map(|f| f.gen_source_code(sema_scope, many_formatter, cfg))
|
||||||
f.gen_source_code(sema_scope, many_formatter, prefer_no_std, prefer_prelude)
|
|
||||||
})
|
|
||||||
.collect::<Result<Vec<String>, DisplaySourceCodeError>>()?
|
.collect::<Result<Vec<String>, DisplaySourceCodeError>>()?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.join(", ");
|
.join(", ");
|
||||||
|
@ -167,14 +160,10 @@ impl Expr {
|
||||||
crate::AssocItemContainer::Impl(imp) => {
|
crate::AssocItemContainer::Impl(imp) => {
|
||||||
let self_ty = imp.self_ty(db);
|
let self_ty = imp.self_ty(db);
|
||||||
// Should it be guaranteed that `mod_item_path` always exists?
|
// Should it be guaranteed that `mod_item_path` always exists?
|
||||||
match self_ty.as_adt().and_then(|adt| {
|
match self_ty
|
||||||
mod_item_path(
|
.as_adt()
|
||||||
sema_scope,
|
.and_then(|adt| mod_item_path(sema_scope, &adt.into(), cfg))
|
||||||
&adt.into(),
|
{
|
||||||
prefer_no_std,
|
|
||||||
prefer_prelude,
|
|
||||||
)
|
|
||||||
}) {
|
|
||||||
Some(path) => path.display(sema_scope.db.upcast()).to_string(),
|
Some(path) => path.display(sema_scope.db.upcast()).to_string(),
|
||||||
None => self_ty.display(db).to_string(),
|
None => self_ty.display(db).to_string(),
|
||||||
}
|
}
|
||||||
|
@ -196,17 +185,10 @@ impl Expr {
|
||||||
|
|
||||||
let func_name = func.name(db).display(db.upcast()).to_string();
|
let func_name = func.name(db).display(db.upcast()).to_string();
|
||||||
let self_param = func.self_param(db).unwrap();
|
let self_param = func.self_param(db).unwrap();
|
||||||
let target_str = target.gen_source_code(
|
let target_str = target.gen_source_code(sema_scope, many_formatter, cfg)?;
|
||||||
sema_scope,
|
|
||||||
many_formatter,
|
|
||||||
prefer_no_std,
|
|
||||||
prefer_prelude,
|
|
||||||
)?;
|
|
||||||
let args = params
|
let args = params
|
||||||
.iter()
|
.iter()
|
||||||
.map(|f| {
|
.map(|f| f.gen_source_code(sema_scope, many_formatter, cfg))
|
||||||
f.gen_source_code(sema_scope, many_formatter, prefer_no_std, prefer_prelude)
|
|
||||||
})
|
|
||||||
.collect::<Result<Vec<String>, DisplaySourceCodeError>>()?
|
.collect::<Result<Vec<String>, DisplaySourceCodeError>>()?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.join(", ");
|
.join(", ");
|
||||||
|
@ -238,7 +220,7 @@ impl Expr {
|
||||||
false => {
|
false => {
|
||||||
let generics = generics
|
let generics = generics
|
||||||
.iter()
|
.iter()
|
||||||
.map(|it| type_path(sema_scope, it, prefer_no_std, prefer_prelude))
|
.map(|it| type_path(sema_scope, it, cfg))
|
||||||
.collect::<Result<Vec<String>, DisplaySourceCodeError>>()?
|
.collect::<Result<Vec<String>, DisplaySourceCodeError>>()?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.join(", ");
|
.join(", ");
|
||||||
|
@ -249,14 +231,7 @@ impl Expr {
|
||||||
StructKind::Tuple => {
|
StructKind::Tuple => {
|
||||||
let args = params
|
let args = params
|
||||||
.iter()
|
.iter()
|
||||||
.map(|f| {
|
.map(|f| f.gen_source_code(sema_scope, many_formatter, cfg))
|
||||||
f.gen_source_code(
|
|
||||||
sema_scope,
|
|
||||||
many_formatter,
|
|
||||||
prefer_no_std,
|
|
||||||
prefer_prelude,
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.collect::<Result<Vec<String>, DisplaySourceCodeError>>()?
|
.collect::<Result<Vec<String>, DisplaySourceCodeError>>()?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.join(", ");
|
.join(", ");
|
||||||
|
@ -271,12 +246,7 @@ impl Expr {
|
||||||
let tmp = format!(
|
let tmp = format!(
|
||||||
"{}: {}",
|
"{}: {}",
|
||||||
f.name(db).display(db.upcast()),
|
f.name(db).display(db.upcast()),
|
||||||
a.gen_source_code(
|
a.gen_source_code(sema_scope, many_formatter, cfg)?
|
||||||
sema_scope,
|
|
||||||
many_formatter,
|
|
||||||
prefer_no_std,
|
|
||||||
prefer_prelude
|
|
||||||
)?
|
|
||||||
);
|
);
|
||||||
Ok(tmp)
|
Ok(tmp)
|
||||||
})
|
})
|
||||||
|
@ -297,14 +267,7 @@ impl Expr {
|
||||||
StructKind::Tuple => {
|
StructKind::Tuple => {
|
||||||
let args = params
|
let args = params
|
||||||
.iter()
|
.iter()
|
||||||
.map(|a| {
|
.map(|a| a.gen_source_code(sema_scope, many_formatter, cfg))
|
||||||
a.gen_source_code(
|
|
||||||
sema_scope,
|
|
||||||
many_formatter,
|
|
||||||
prefer_no_std,
|
|
||||||
prefer_prelude,
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.collect::<Result<Vec<String>, DisplaySourceCodeError>>()?
|
.collect::<Result<Vec<String>, DisplaySourceCodeError>>()?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.join(", ");
|
.join(", ");
|
||||||
|
@ -319,12 +282,7 @@ impl Expr {
|
||||||
let tmp = format!(
|
let tmp = format!(
|
||||||
"{}: {}",
|
"{}: {}",
|
||||||
f.name(db).display(db.upcast()),
|
f.name(db).display(db.upcast()),
|
||||||
a.gen_source_code(
|
a.gen_source_code(sema_scope, many_formatter, cfg)?
|
||||||
sema_scope,
|
|
||||||
many_formatter,
|
|
||||||
prefer_no_std,
|
|
||||||
prefer_prelude
|
|
||||||
)?
|
|
||||||
);
|
);
|
||||||
Ok(tmp)
|
Ok(tmp)
|
||||||
})
|
})
|
||||||
|
@ -338,7 +296,7 @@ impl Expr {
|
||||||
false => {
|
false => {
|
||||||
let generics = generics
|
let generics = generics
|
||||||
.iter()
|
.iter()
|
||||||
.map(|it| type_path(sema_scope, it, prefer_no_std, prefer_prelude))
|
.map(|it| type_path(sema_scope, it, cfg))
|
||||||
.collect::<Result<Vec<String>, DisplaySourceCodeError>>()?
|
.collect::<Result<Vec<String>, DisplaySourceCodeError>>()?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.join(", ");
|
.join(", ");
|
||||||
|
@ -353,9 +311,7 @@ impl Expr {
|
||||||
Expr::Tuple { params, .. } => {
|
Expr::Tuple { params, .. } => {
|
||||||
let args = params
|
let args = params
|
||||||
.iter()
|
.iter()
|
||||||
.map(|a| {
|
.map(|a| a.gen_source_code(sema_scope, many_formatter, cfg))
|
||||||
a.gen_source_code(sema_scope, many_formatter, prefer_no_std, prefer_prelude)
|
|
||||||
})
|
|
||||||
.collect::<Result<Vec<String>, DisplaySourceCodeError>>()?
|
.collect::<Result<Vec<String>, DisplaySourceCodeError>>()?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.join(", ");
|
.join(", ");
|
||||||
|
@ -367,12 +323,7 @@ impl Expr {
|
||||||
return Ok(many_formatter(&expr.ty(db)));
|
return Ok(many_formatter(&expr.ty(db)));
|
||||||
}
|
}
|
||||||
|
|
||||||
let strukt = expr.gen_source_code(
|
let strukt = expr.gen_source_code(sema_scope, many_formatter, cfg)?;
|
||||||
sema_scope,
|
|
||||||
many_formatter,
|
|
||||||
prefer_no_std,
|
|
||||||
prefer_prelude,
|
|
||||||
)?;
|
|
||||||
let field = field.name(db).display(db.upcast()).to_string();
|
let field = field.name(db).display(db.upcast()).to_string();
|
||||||
Ok(format!("{strukt}.{field}"))
|
Ok(format!("{strukt}.{field}"))
|
||||||
}
|
}
|
||||||
|
@ -381,12 +332,7 @@ impl Expr {
|
||||||
return Ok(many_formatter(&expr.ty(db)));
|
return Ok(many_formatter(&expr.ty(db)));
|
||||||
}
|
}
|
||||||
|
|
||||||
let inner = expr.gen_source_code(
|
let inner = expr.gen_source_code(sema_scope, many_formatter, cfg)?;
|
||||||
sema_scope,
|
|
||||||
many_formatter,
|
|
||||||
prefer_no_std,
|
|
||||||
prefer_prelude,
|
|
||||||
)?;
|
|
||||||
Ok(format!("&{inner}"))
|
Ok(format!("&{inner}"))
|
||||||
}
|
}
|
||||||
Expr::Many(ty) => Ok(many_formatter(ty)),
|
Expr::Many(ty) => Ok(many_formatter(ty)),
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use std::iter::{self, Peekable};
|
use std::iter::{self, Peekable};
|
||||||
|
|
||||||
use either::Either;
|
use either::Either;
|
||||||
use hir::{Adt, Crate, HasAttrs, HasSource, ModuleDef, Semantics};
|
use hir::{Adt, Crate, HasAttrs, HasSource, ImportPathConfig, ModuleDef, Semantics};
|
||||||
use ide_db::RootDatabase;
|
use ide_db::RootDatabase;
|
||||||
use ide_db::{famous_defs::FamousDefs, helpers::mod_path_to_ast};
|
use ide_db::{famous_defs::FamousDefs, helpers::mod_path_to_ast};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
|
@ -71,6 +71,11 @@ pub(crate) fn add_missing_match_arms(acc: &mut Assists, ctx: &AssistContext<'_>)
|
||||||
.filter(|pat| !matches!(pat, Pat::WildcardPat(_)))
|
.filter(|pat| !matches!(pat, Pat::WildcardPat(_)))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
let cfg = ImportPathConfig {
|
||||||
|
prefer_no_std: ctx.config.prefer_no_std,
|
||||||
|
prefer_prelude: ctx.config.prefer_prelude,
|
||||||
|
};
|
||||||
|
|
||||||
let module = ctx.sema.scope(expr.syntax())?.module();
|
let module = ctx.sema.scope(expr.syntax())?.module();
|
||||||
let (mut missing_pats, is_non_exhaustive, has_hidden_variants): (
|
let (mut missing_pats, is_non_exhaustive, has_hidden_variants): (
|
||||||
Peekable<Box<dyn Iterator<Item = (ast::Pat, bool)>>>,
|
Peekable<Box<dyn Iterator<Item = (ast::Pat, bool)>>>,
|
||||||
|
@ -88,13 +93,7 @@ pub(crate) fn add_missing_match_arms(acc: &mut Assists, ctx: &AssistContext<'_>)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|variant| {
|
.filter_map(|variant| {
|
||||||
Some((
|
Some((
|
||||||
build_pat(
|
build_pat(ctx.db(), module, variant, cfg)?,
|
||||||
ctx.db(),
|
|
||||||
module,
|
|
||||||
variant,
|
|
||||||
ctx.config.prefer_no_std,
|
|
||||||
ctx.config.prefer_prelude,
|
|
||||||
)?,
|
|
||||||
variant.should_be_hidden(ctx.db(), module.krate()),
|
variant.should_be_hidden(ctx.db(), module.krate()),
|
||||||
))
|
))
|
||||||
})
|
})
|
||||||
|
@ -145,15 +144,9 @@ pub(crate) fn add_missing_match_arms(acc: &mut Assists, ctx: &AssistContext<'_>)
|
||||||
let is_hidden = variants
|
let is_hidden = variants
|
||||||
.iter()
|
.iter()
|
||||||
.any(|variant| variant.should_be_hidden(ctx.db(), module.krate()));
|
.any(|variant| variant.should_be_hidden(ctx.db(), module.krate()));
|
||||||
let patterns = variants.into_iter().filter_map(|variant| {
|
let patterns = variants
|
||||||
build_pat(
|
.into_iter()
|
||||||
ctx.db(),
|
.filter_map(|variant| build_pat(ctx.db(), module, variant, cfg));
|
||||||
module,
|
|
||||||
variant,
|
|
||||||
ctx.config.prefer_no_std,
|
|
||||||
ctx.config.prefer_prelude,
|
|
||||||
)
|
|
||||||
});
|
|
||||||
|
|
||||||
(ast::Pat::from(make::tuple_pat(patterns)), is_hidden)
|
(ast::Pat::from(make::tuple_pat(patterns)), is_hidden)
|
||||||
})
|
})
|
||||||
|
@ -184,15 +177,9 @@ pub(crate) fn add_missing_match_arms(acc: &mut Assists, ctx: &AssistContext<'_>)
|
||||||
let is_hidden = variants
|
let is_hidden = variants
|
||||||
.iter()
|
.iter()
|
||||||
.any(|variant| variant.should_be_hidden(ctx.db(), module.krate()));
|
.any(|variant| variant.should_be_hidden(ctx.db(), module.krate()));
|
||||||
let patterns = variants.into_iter().filter_map(|variant| {
|
let patterns = variants
|
||||||
build_pat(
|
.into_iter()
|
||||||
ctx.db(),
|
.filter_map(|variant| build_pat(ctx.db(), module, variant, cfg));
|
||||||
module,
|
|
||||||
variant,
|
|
||||||
ctx.config.prefer_no_std,
|
|
||||||
ctx.config.prefer_prelude,
|
|
||||||
)
|
|
||||||
});
|
|
||||||
(ast::Pat::from(make::slice_pat(patterns)), is_hidden)
|
(ast::Pat::from(make::slice_pat(patterns)), is_hidden)
|
||||||
})
|
})
|
||||||
.filter(|(variant_pat, _)| is_variant_missing(&top_lvl_pats, variant_pat));
|
.filter(|(variant_pat, _)| is_variant_missing(&top_lvl_pats, variant_pat));
|
||||||
|
@ -457,18 +444,11 @@ fn build_pat(
|
||||||
db: &RootDatabase,
|
db: &RootDatabase,
|
||||||
module: hir::Module,
|
module: hir::Module,
|
||||||
var: ExtendedVariant,
|
var: ExtendedVariant,
|
||||||
prefer_no_std: bool,
|
cfg: ImportPathConfig,
|
||||||
prefer_prelude: bool,
|
|
||||||
) -> Option<ast::Pat> {
|
) -> Option<ast::Pat> {
|
||||||
match var {
|
match var {
|
||||||
ExtendedVariant::Variant(var) => {
|
ExtendedVariant::Variant(var) => {
|
||||||
let path = mod_path_to_ast(&module.find_path(
|
let path = mod_path_to_ast(&module.find_path(db, ModuleDef::from(var), cfg)?);
|
||||||
db,
|
|
||||||
ModuleDef::from(var),
|
|
||||||
prefer_no_std,
|
|
||||||
prefer_prelude,
|
|
||||||
)?);
|
|
||||||
|
|
||||||
// FIXME: use HIR for this; it doesn't currently expose struct vs. tuple vs. unit variants though
|
// FIXME: use HIR for this; it doesn't currently expose struct vs. tuple vs. unit variants though
|
||||||
Some(match var.source(db)?.value.kind() {
|
Some(match var.source(db)?.value.kind() {
|
||||||
ast::StructKind::Tuple(field_list) => {
|
ast::StructKind::Tuple(field_list) => {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use std::cmp::Reverse;
|
use std::cmp::Reverse;
|
||||||
|
|
||||||
use hir::{db::HirDatabase, Module};
|
use hir::{db::HirDatabase, ImportPathConfig, Module};
|
||||||
use ide_db::{
|
use ide_db::{
|
||||||
helpers::mod_path_to_ast,
|
helpers::mod_path_to_ast,
|
||||||
imports::{
|
imports::{
|
||||||
|
@ -90,14 +90,14 @@ use crate::{AssistContext, AssistId, AssistKind, Assists, GroupLabel};
|
||||||
// # pub mod std { pub mod collections { pub struct HashMap { } } }
|
// # pub mod std { pub mod collections { pub struct HashMap { } } }
|
||||||
// ```
|
// ```
|
||||||
pub(crate) fn auto_import(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
|
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,
|
||||||
|
};
|
||||||
|
|
||||||
let (import_assets, syntax_under_caret) = find_importable_node(ctx)?;
|
let (import_assets, syntax_under_caret) = find_importable_node(ctx)?;
|
||||||
let mut proposed_imports: Vec<_> = import_assets
|
let mut proposed_imports: Vec<_> = import_assets
|
||||||
.search_for_imports(
|
.search_for_imports(&ctx.sema, cfg, ctx.config.insert_use.prefix_kind)
|
||||||
&ctx.sema,
|
|
||||||
ctx.config.insert_use.prefix_kind,
|
|
||||||
ctx.config.prefer_no_std,
|
|
||||||
ctx.config.prefer_no_std,
|
|
||||||
)
|
|
||||||
.collect();
|
.collect();
|
||||||
if proposed_imports.is_empty() {
|
if proposed_imports.is_empty() {
|
||||||
return None;
|
return None;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use hir::ModuleDef;
|
use hir::{ImportPathConfig, ModuleDef};
|
||||||
use ide_db::{
|
use ide_db::{
|
||||||
assists::{AssistId, AssistKind},
|
assists::{AssistId, AssistKind},
|
||||||
defs::Definition,
|
defs::Definition,
|
||||||
|
@ -326,6 +326,11 @@ fn augment_references_with_imports(
|
||||||
) -> Vec<FileReferenceWithImport> {
|
) -> Vec<FileReferenceWithImport> {
|
||||||
let mut visited_modules = FxHashSet::default();
|
let mut visited_modules = FxHashSet::default();
|
||||||
|
|
||||||
|
let cfg = ImportPathConfig {
|
||||||
|
prefer_no_std: ctx.config.prefer_no_std,
|
||||||
|
prefer_prelude: ctx.config.prefer_prelude,
|
||||||
|
};
|
||||||
|
|
||||||
references
|
references
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|FileReference { range, name, .. }| {
|
.filter_map(|FileReference { range, name, .. }| {
|
||||||
|
@ -345,8 +350,7 @@ fn augment_references_with_imports(
|
||||||
ctx.sema.db,
|
ctx.sema.db,
|
||||||
ModuleDef::Module(*target_module),
|
ModuleDef::Module(*target_module),
|
||||||
ctx.config.insert_use.prefix_kind,
|
ctx.config.insert_use.prefix_kind,
|
||||||
ctx.config.prefer_no_std,
|
cfg,
|
||||||
ctx.config.prefer_prelude,
|
|
||||||
)
|
)
|
||||||
.map(|mod_path| {
|
.map(|mod_path| {
|
||||||
make::path_concat(mod_path_to_ast(&mod_path), make::path_from_text("Bool"))
|
make::path_concat(mod_path_to_ast(&mod_path), make::path_from_text("Bool"))
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use hir::ImportPathConfig;
|
||||||
use ide_db::{famous_defs::FamousDefs, helpers::mod_path_to_ast, traits::resolve_target_trait};
|
use ide_db::{famous_defs::FamousDefs, helpers::mod_path_to_ast, traits::resolve_target_trait};
|
||||||
use syntax::ast::{self, AstNode, HasName};
|
use syntax::ast::{self, AstNode, HasName};
|
||||||
|
|
||||||
|
@ -43,19 +44,18 @@ pub(crate) fn convert_into_to_from(acc: &mut Assists, ctx: &AssistContext<'_>) -
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let cfg = ImportPathConfig {
|
||||||
|
prefer_no_std: ctx.config.prefer_no_std,
|
||||||
|
prefer_prelude: ctx.config.prefer_prelude,
|
||||||
|
};
|
||||||
|
|
||||||
let src_type_path = {
|
let src_type_path = {
|
||||||
let src_type_path = src_type.syntax().descendants().find_map(ast::Path::cast)?;
|
let src_type_path = src_type.syntax().descendants().find_map(ast::Path::cast)?;
|
||||||
let src_type_def = match ctx.sema.resolve_path(&src_type_path) {
|
let src_type_def = match ctx.sema.resolve_path(&src_type_path) {
|
||||||
Some(hir::PathResolution::Def(module_def)) => module_def,
|
Some(hir::PathResolution::Def(module_def)) => module_def,
|
||||||
_ => return None,
|
_ => return None,
|
||||||
};
|
};
|
||||||
|
mod_path_to_ast(&module.find_path(ctx.db(), src_type_def, cfg)?)
|
||||||
mod_path_to_ast(&module.find_path(
|
|
||||||
ctx.db(),
|
|
||||||
src_type_def,
|
|
||||||
ctx.config.prefer_no_std,
|
|
||||||
ctx.config.prefer_prelude,
|
|
||||||
)?)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let dest_type = match &ast_trait {
|
let dest_type = match &ast_trait {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use either::Either;
|
use either::Either;
|
||||||
use hir::ModuleDef;
|
use hir::{ImportPathConfig, ModuleDef};
|
||||||
use ide_db::{
|
use ide_db::{
|
||||||
assists::{AssistId, AssistKind},
|
assists::{AssistId, AssistKind},
|
||||||
defs::Definition,
|
defs::Definition,
|
||||||
|
@ -183,6 +183,11 @@ fn augment_references_with_imports(
|
||||||
) -> Vec<(ast::NameLike, Option<(ImportScope, ast::Path)>)> {
|
) -> Vec<(ast::NameLike, Option<(ImportScope, ast::Path)>)> {
|
||||||
let mut visited_modules = FxHashSet::default();
|
let mut visited_modules = FxHashSet::default();
|
||||||
|
|
||||||
|
let cfg = ImportPathConfig {
|
||||||
|
prefer_no_std: ctx.config.prefer_no_std,
|
||||||
|
prefer_prelude: ctx.config.prefer_prelude,
|
||||||
|
};
|
||||||
|
|
||||||
references
|
references
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|FileReference { name, .. }| {
|
.filter_map(|FileReference { name, .. }| {
|
||||||
|
@ -205,8 +210,7 @@ fn augment_references_with_imports(
|
||||||
ctx.sema.db,
|
ctx.sema.db,
|
||||||
ModuleDef::Module(*target_module),
|
ModuleDef::Module(*target_module),
|
||||||
ctx.config.insert_use.prefix_kind,
|
ctx.config.insert_use.prefix_kind,
|
||||||
ctx.config.prefer_no_std,
|
cfg,
|
||||||
ctx.config.prefer_prelude,
|
|
||||||
)
|
)
|
||||||
.map(|mod_path| {
|
.map(|mod_path| {
|
||||||
make::path_concat(
|
make::path_concat(
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use hir::HasVisibility;
|
use hir::{HasVisibility, ImportPathConfig};
|
||||||
use ide_db::{
|
use ide_db::{
|
||||||
assists::{AssistId, AssistKind},
|
assists::{AssistId, AssistKind},
|
||||||
defs::Definition,
|
defs::Definition,
|
||||||
|
@ -87,15 +87,15 @@ fn collect_data(ident_pat: ast::IdentPat, ctx: &AssistContext<'_>) -> Option<Str
|
||||||
let ty = ctx.sema.type_of_binding_in_pat(&ident_pat)?;
|
let ty = ctx.sema.type_of_binding_in_pat(&ident_pat)?;
|
||||||
let hir::Adt::Struct(struct_type) = ty.strip_references().as_adt()? else { return None };
|
let hir::Adt::Struct(struct_type) = ty.strip_references().as_adt()? else { return None };
|
||||||
|
|
||||||
|
let cfg = ImportPathConfig {
|
||||||
|
prefer_no_std: ctx.config.prefer_no_std,
|
||||||
|
prefer_prelude: ctx.config.prefer_prelude,
|
||||||
|
};
|
||||||
|
|
||||||
let module = ctx.sema.scope(ident_pat.syntax())?.module();
|
let module = ctx.sema.scope(ident_pat.syntax())?.module();
|
||||||
let struct_def = hir::ModuleDef::from(struct_type);
|
let struct_def = hir::ModuleDef::from(struct_type);
|
||||||
let kind = struct_type.kind(ctx.db());
|
let kind = struct_type.kind(ctx.db());
|
||||||
let struct_def_path = module.find_path(
|
let struct_def_path = module.find_path(ctx.db(), struct_def, cfg)?;
|
||||||
ctx.db(),
|
|
||||||
struct_def,
|
|
||||||
ctx.config.prefer_no_std,
|
|
||||||
ctx.config.prefer_prelude,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
let is_non_exhaustive = struct_def.attrs(ctx.db())?.by_key("non_exhaustive").exists();
|
let is_non_exhaustive = struct_def.attrs(ctx.db())?.by_key("non_exhaustive").exists();
|
||||||
let is_foreign_crate =
|
let is_foreign_crate =
|
||||||
|
|
|
@ -3,8 +3,8 @@ use std::{iter, ops::RangeInclusive};
|
||||||
use ast::make;
|
use ast::make;
|
||||||
use either::Either;
|
use either::Either;
|
||||||
use hir::{
|
use hir::{
|
||||||
DescendPreference, HasSource, HirDisplay, InFile, Local, LocalSource, ModuleDef,
|
DescendPreference, HasSource, HirDisplay, ImportPathConfig, InFile, Local, LocalSource,
|
||||||
PathResolution, Semantics, TypeInfo, TypeParam,
|
ModuleDef, PathResolution, Semantics, TypeInfo, TypeParam,
|
||||||
};
|
};
|
||||||
use ide_db::{
|
use ide_db::{
|
||||||
defs::{Definition, NameRefClass},
|
defs::{Definition, NameRefClass},
|
||||||
|
@ -213,8 +213,10 @@ pub(crate) fn extract_function(acc: &mut Assists, ctx: &AssistContext<'_>) -> Op
|
||||||
ctx.sema.db,
|
ctx.sema.db,
|
||||||
ModuleDef::from(control_flow_enum),
|
ModuleDef::from(control_flow_enum),
|
||||||
ctx.config.insert_use.prefix_kind,
|
ctx.config.insert_use.prefix_kind,
|
||||||
ctx.config.prefer_no_std,
|
ImportPathConfig {
|
||||||
ctx.config.prefer_prelude,
|
prefer_no_std: ctx.config.prefer_no_std,
|
||||||
|
prefer_prelude: ctx.config.prefer_prelude,
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
if let Some(mod_path) = mod_path {
|
if let Some(mod_path) = mod_path {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use std::iter;
|
use std::iter;
|
||||||
|
|
||||||
use either::Either;
|
use either::Either;
|
||||||
use hir::{Module, ModuleDef, Name, Variant};
|
use hir::{ImportPathConfig, Module, ModuleDef, Name, Variant};
|
||||||
use ide_db::{
|
use ide_db::{
|
||||||
defs::Definition,
|
defs::Definition,
|
||||||
helpers::mod_path_to_ast,
|
helpers::mod_path_to_ast,
|
||||||
|
@ -390,8 +390,10 @@ fn process_references(
|
||||||
ctx.sema.db,
|
ctx.sema.db,
|
||||||
*enum_module_def,
|
*enum_module_def,
|
||||||
ctx.config.insert_use.prefix_kind,
|
ctx.config.insert_use.prefix_kind,
|
||||||
ctx.config.prefer_no_std,
|
ImportPathConfig {
|
||||||
ctx.config.prefer_prelude,
|
prefer_no_std: ctx.config.prefer_no_std,
|
||||||
|
prefer_prelude: ctx.config.prefer_prelude,
|
||||||
|
},
|
||||||
);
|
);
|
||||||
if let Some(mut mod_path) = mod_path {
|
if let Some(mut mod_path) = mod_path {
|
||||||
mod_path.pop_segment();
|
mod_path.pop_segment();
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
|
|
||||||
use hir::{ModPath, ModuleDef};
|
use hir::{ImportPathConfig, ModPath, ModuleDef};
|
||||||
use ide_db::{famous_defs::FamousDefs, RootDatabase};
|
use ide_db::{famous_defs::FamousDefs, RootDatabase};
|
||||||
use syntax::{
|
use syntax::{
|
||||||
ast::{self, HasName},
|
ast::{self, HasName},
|
||||||
|
@ -61,8 +61,10 @@ fn generate_record_deref(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<(
|
||||||
let trait_path = module.find_path(
|
let trait_path = module.find_path(
|
||||||
ctx.db(),
|
ctx.db(),
|
||||||
ModuleDef::Trait(trait_),
|
ModuleDef::Trait(trait_),
|
||||||
ctx.config.prefer_no_std,
|
ImportPathConfig {
|
||||||
ctx.config.prefer_prelude,
|
prefer_no_std: ctx.config.prefer_no_std,
|
||||||
|
prefer_prelude: ctx.config.prefer_prelude,
|
||||||
|
},
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let field_type = field.ty()?;
|
let field_type = field.ty()?;
|
||||||
|
@ -106,8 +108,10 @@ fn generate_tuple_deref(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()
|
||||||
let trait_path = module.find_path(
|
let trait_path = module.find_path(
|
||||||
ctx.db(),
|
ctx.db(),
|
||||||
ModuleDef::Trait(trait_),
|
ModuleDef::Trait(trait_),
|
||||||
ctx.config.prefer_no_std,
|
ImportPathConfig {
|
||||||
ctx.config.prefer_prelude,
|
prefer_no_std: ctx.config.prefer_no_std,
|
||||||
|
prefer_prelude: ctx.config.prefer_prelude,
|
||||||
|
},
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let field_type = field.ty()?;
|
let field_type = field.ty()?;
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use hir::ImportPathConfig;
|
||||||
use ide_db::{
|
use ide_db::{
|
||||||
imports::import_assets::item_for_path_search, use_trivial_constructor::use_trivial_constructor,
|
imports::import_assets::item_for_path_search, use_trivial_constructor::use_trivial_constructor,
|
||||||
};
|
};
|
||||||
|
@ -61,8 +62,10 @@ pub(crate) fn generate_new(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option
|
||||||
let type_path = current_module.find_path(
|
let type_path = current_module.find_path(
|
||||||
ctx.sema.db,
|
ctx.sema.db,
|
||||||
item_for_path_search(ctx.sema.db, item_in_ns)?,
|
item_for_path_search(ctx.sema.db, item_in_ns)?,
|
||||||
ctx.config.prefer_no_std,
|
ImportPathConfig {
|
||||||
ctx.config.prefer_prelude,
|
prefer_no_std: ctx.config.prefer_no_std,
|
||||||
|
prefer_prelude: ctx.config.prefer_prelude,
|
||||||
|
},
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let expr = use_trivial_constructor(
|
let expr = use_trivial_constructor(
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
use hir::{db::HirDatabase, AsAssocItem, AssocItem, AssocItemContainer, ItemInNs, ModuleDef};
|
use hir::{
|
||||||
|
db::HirDatabase, AsAssocItem, AssocItem, AssocItemContainer, ImportPathConfig, ItemInNs,
|
||||||
|
ModuleDef,
|
||||||
|
};
|
||||||
use ide_db::assists::{AssistId, AssistKind};
|
use ide_db::assists::{AssistId, AssistKind};
|
||||||
use syntax::{ast, AstNode};
|
use syntax::{ast, AstNode};
|
||||||
|
|
||||||
|
@ -47,8 +50,10 @@ pub(crate) fn qualify_method_call(acc: &mut Assists, ctx: &AssistContext<'_>) ->
|
||||||
let receiver_path = current_module.find_path(
|
let receiver_path = current_module.find_path(
|
||||||
ctx.sema.db,
|
ctx.sema.db,
|
||||||
item_for_path_search(ctx.sema.db, item_in_ns)?,
|
item_for_path_search(ctx.sema.db, item_in_ns)?,
|
||||||
ctx.config.prefer_no_std,
|
ImportPathConfig {
|
||||||
ctx.config.prefer_prelude,
|
prefer_no_std: ctx.config.prefer_no_std,
|
||||||
|
prefer_prelude: ctx.config.prefer_prelude,
|
||||||
|
},
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let qualify_candidate = QualifyCandidate::ImplMethod(ctx.sema.db, call, resolved_call);
|
let qualify_candidate = QualifyCandidate::ImplMethod(ctx.sema.db, call, resolved_call);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use std::iter;
|
use std::iter;
|
||||||
|
|
||||||
use hir::AsAssocItem;
|
use hir::{AsAssocItem, ImportPathConfig};
|
||||||
use ide_db::RootDatabase;
|
use ide_db::RootDatabase;
|
||||||
use ide_db::{
|
use ide_db::{
|
||||||
helpers::mod_path_to_ast,
|
helpers::mod_path_to_ast,
|
||||||
|
@ -37,9 +37,13 @@ use crate::{
|
||||||
// ```
|
// ```
|
||||||
pub(crate) fn qualify_path(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
|
pub(crate) fn qualify_path(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
|
||||||
let (import_assets, syntax_under_caret) = find_importable_node(ctx)?;
|
let (import_assets, syntax_under_caret) = find_importable_node(ctx)?;
|
||||||
let mut proposed_imports: Vec<_> = import_assets
|
let cfg = ImportPathConfig {
|
||||||
.search_for_relative_paths(&ctx.sema, ctx.config.prefer_no_std, ctx.config.prefer_prelude)
|
prefer_no_std: ctx.config.prefer_no_std,
|
||||||
.collect();
|
prefer_prelude: ctx.config.prefer_prelude,
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut proposed_imports: Vec<_> =
|
||||||
|
import_assets.search_for_relative_paths(&ctx.sema, cfg).collect();
|
||||||
if proposed_imports.is_empty() {
|
if proposed_imports.is_empty() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use hir::{InFile, MacroFileIdExt, ModuleDef};
|
use hir::{ImportPathConfig, InFile, MacroFileIdExt, ModuleDef};
|
||||||
use ide_db::{helpers::mod_path_to_ast, imports::import_assets::NameToImport, items_locator};
|
use ide_db::{helpers::mod_path_to_ast, imports::import_assets::NameToImport, items_locator};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use syntax::{
|
use syntax::{
|
||||||
|
@ -86,8 +86,10 @@ pub(crate) fn replace_derive_with_manual_impl(
|
||||||
.find_path(
|
.find_path(
|
||||||
ctx.sema.db,
|
ctx.sema.db,
|
||||||
hir::ModuleDef::Trait(trait_),
|
hir::ModuleDef::Trait(trait_),
|
||||||
ctx.config.prefer_no_std,
|
ImportPathConfig {
|
||||||
ctx.config.prefer_prelude,
|
prefer_no_std: ctx.config.prefer_no_std,
|
||||||
|
prefer_prelude: ctx.config.prefer_prelude,
|
||||||
|
},
|
||||||
)
|
)
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(mod_path_to_ast)
|
.map(mod_path_to_ast)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use hir::AsAssocItem;
|
use hir::{AsAssocItem, ImportPathConfig};
|
||||||
use ide_db::{
|
use ide_db::{
|
||||||
helpers::mod_path_to_ast,
|
helpers::mod_path_to_ast,
|
||||||
imports::insert_use::{insert_use, ImportScope},
|
imports::insert_use::{insert_use, ImportScope},
|
||||||
|
@ -67,8 +67,10 @@ pub(crate) fn replace_qualified_name_with_use(
|
||||||
ctx.sema.db,
|
ctx.sema.db,
|
||||||
module,
|
module,
|
||||||
ctx.config.insert_use.prefix_kind,
|
ctx.config.insert_use.prefix_kind,
|
||||||
ctx.config.prefer_no_std,
|
ImportPathConfig {
|
||||||
ctx.config.prefer_prelude,
|
prefer_no_std: ctx.config.prefer_no_std,
|
||||||
|
prefer_prelude: ctx.config.prefer_prelude,
|
||||||
|
},
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.flatten();
|
.flatten();
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
//! Term search assist
|
//! Term search assist
|
||||||
use hir::term_search::{TermSearchConfig, TermSearchCtx};
|
use hir::{
|
||||||
|
term_search::{TermSearchConfig, TermSearchCtx},
|
||||||
|
ImportPathConfig,
|
||||||
|
};
|
||||||
use ide_db::{
|
use ide_db::{
|
||||||
assists::{AssistId, AssistKind, GroupLabel},
|
assists::{AssistId, AssistKind, GroupLabel},
|
||||||
famous_defs::FamousDefs,
|
famous_defs::FamousDefs,
|
||||||
|
@ -50,8 +53,10 @@ pub(crate) fn term_search(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<
|
||||||
path.gen_source_code(
|
path.gen_source_code(
|
||||||
&scope,
|
&scope,
|
||||||
&mut formatter,
|
&mut formatter,
|
||||||
ctx.config.prefer_no_std,
|
ImportPathConfig {
|
||||||
ctx.config.prefer_prelude,
|
prefer_no_std: ctx.config.prefer_no_std,
|
||||||
|
prefer_prelude: ctx.config.prefer_prelude,
|
||||||
|
},
|
||||||
)
|
)
|
||||||
.ok()
|
.ok()
|
||||||
})
|
})
|
||||||
|
|
|
@ -24,7 +24,7 @@ pub(crate) mod vis;
|
||||||
|
|
||||||
use std::iter;
|
use std::iter;
|
||||||
|
|
||||||
use hir::{known, HasAttrs, ScopeDef, Variant};
|
use hir::{known, HasAttrs, ImportPathConfig, ScopeDef, Variant};
|
||||||
use ide_db::{imports::import_assets::LocatedImport, RootDatabase, SymbolKind};
|
use ide_db::{imports::import_assets::LocatedImport, RootDatabase, SymbolKind};
|
||||||
use syntax::{ast, SmolStr};
|
use syntax::{ast, SmolStr};
|
||||||
|
|
||||||
|
@ -636,8 +636,10 @@ fn enum_variants_with_paths(
|
||||||
if let Some(path) = ctx.module.find_path(
|
if let Some(path) = ctx.module.find_path(
|
||||||
ctx.db,
|
ctx.db,
|
||||||
hir::ModuleDef::from(variant),
|
hir::ModuleDef::from(variant),
|
||||||
ctx.config.prefer_no_std,
|
ImportPathConfig {
|
||||||
ctx.config.prefer_prelude,
|
prefer_no_std: ctx.config.prefer_no_std,
|
||||||
|
prefer_prelude: ctx.config.prefer_prelude,
|
||||||
|
},
|
||||||
) {
|
) {
|
||||||
// Variants with trivial paths are already added by the existing completion logic,
|
// Variants with trivial paths are already added by the existing completion logic,
|
||||||
// so we should avoid adding these twice
|
// so we should avoid adding these twice
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
//! Completion of names from the current scope in expression position.
|
//! Completion of names from the current scope in expression position.
|
||||||
|
|
||||||
use hir::ScopeDef;
|
use hir::{ImportPathConfig, ScopeDef};
|
||||||
use syntax::ast;
|
use syntax::ast;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -174,8 +174,10 @@ pub(crate) fn complete_expr_path(
|
||||||
.find_path(
|
.find_path(
|
||||||
ctx.db,
|
ctx.db,
|
||||||
hir::ModuleDef::from(strukt),
|
hir::ModuleDef::from(strukt),
|
||||||
ctx.config.prefer_no_std,
|
ImportPathConfig {
|
||||||
ctx.config.prefer_prelude,
|
prefer_no_std: ctx.config.prefer_no_std,
|
||||||
|
prefer_prelude: ctx.config.prefer_prelude,
|
||||||
|
},
|
||||||
)
|
)
|
||||||
.filter(|it| it.len() > 1);
|
.filter(|it| it.len() > 1);
|
||||||
|
|
||||||
|
@ -197,8 +199,10 @@ pub(crate) fn complete_expr_path(
|
||||||
.find_path(
|
.find_path(
|
||||||
ctx.db,
|
ctx.db,
|
||||||
hir::ModuleDef::from(un),
|
hir::ModuleDef::from(un),
|
||||||
ctx.config.prefer_no_std,
|
ImportPathConfig {
|
||||||
ctx.config.prefer_prelude,
|
prefer_no_std: ctx.config.prefer_no_std,
|
||||||
|
prefer_prelude: ctx.config.prefer_prelude,
|
||||||
|
},
|
||||||
)
|
)
|
||||||
.filter(|it| it.len() > 1);
|
.filter(|it| it.len() > 1);
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
//! See [`import_on_the_fly`].
|
//! See [`import_on_the_fly`].
|
||||||
use hir::{ItemInNs, ModuleDef};
|
use hir::{ImportPathConfig, ItemInNs, ModuleDef};
|
||||||
use ide_db::imports::{
|
use ide_db::imports::{
|
||||||
import_assets::{ImportAssets, LocatedImport},
|
import_assets::{ImportAssets, LocatedImport},
|
||||||
insert_use::ImportScope,
|
insert_use::ImportScope,
|
||||||
|
@ -257,13 +257,13 @@ fn import_on_the_fly(
|
||||||
};
|
};
|
||||||
let user_input_lowercased = potential_import_name.to_lowercase();
|
let user_input_lowercased = potential_import_name.to_lowercase();
|
||||||
|
|
||||||
|
let import_cfg = ImportPathConfig {
|
||||||
|
prefer_no_std: ctx.config.prefer_no_std,
|
||||||
|
prefer_prelude: ctx.config.prefer_prelude,
|
||||||
|
};
|
||||||
|
|
||||||
import_assets
|
import_assets
|
||||||
.search_for_imports(
|
.search_for_imports(&ctx.sema, import_cfg, ctx.config.insert_use.prefix_kind)
|
||||||
&ctx.sema,
|
|
||||||
ctx.config.insert_use.prefix_kind,
|
|
||||||
ctx.config.prefer_no_std,
|
|
||||||
ctx.config.prefer_prelude,
|
|
||||||
)
|
|
||||||
.filter(ns_filter)
|
.filter(ns_filter)
|
||||||
.filter(|import| {
|
.filter(|import| {
|
||||||
let original_item = &import.original_item;
|
let original_item = &import.original_item;
|
||||||
|
@ -308,13 +308,13 @@ fn import_on_the_fly_pat_(
|
||||||
};
|
};
|
||||||
let user_input_lowercased = potential_import_name.to_lowercase();
|
let user_input_lowercased = potential_import_name.to_lowercase();
|
||||||
|
|
||||||
|
let cfg = ImportPathConfig {
|
||||||
|
prefer_no_std: ctx.config.prefer_no_std,
|
||||||
|
prefer_prelude: ctx.config.prefer_prelude,
|
||||||
|
};
|
||||||
|
|
||||||
import_assets
|
import_assets
|
||||||
.search_for_imports(
|
.search_for_imports(&ctx.sema, cfg, ctx.config.insert_use.prefix_kind)
|
||||||
&ctx.sema,
|
|
||||||
ctx.config.insert_use.prefix_kind,
|
|
||||||
ctx.config.prefer_no_std,
|
|
||||||
ctx.config.prefer_prelude,
|
|
||||||
)
|
|
||||||
.filter(ns_filter)
|
.filter(ns_filter)
|
||||||
.filter(|import| {
|
.filter(|import| {
|
||||||
let original_item = &import.original_item;
|
let original_item = &import.original_item;
|
||||||
|
@ -355,13 +355,13 @@ fn import_on_the_fly_method(
|
||||||
|
|
||||||
let user_input_lowercased = potential_import_name.to_lowercase();
|
let user_input_lowercased = potential_import_name.to_lowercase();
|
||||||
|
|
||||||
|
let cfg = ImportPathConfig {
|
||||||
|
prefer_no_std: ctx.config.prefer_no_std,
|
||||||
|
prefer_prelude: ctx.config.prefer_prelude,
|
||||||
|
};
|
||||||
|
|
||||||
import_assets
|
import_assets
|
||||||
.search_for_imports(
|
.search_for_imports(&ctx.sema, cfg, ctx.config.insert_use.prefix_kind)
|
||||||
&ctx.sema,
|
|
||||||
ctx.config.insert_use.prefix_kind,
|
|
||||||
ctx.config.prefer_no_std,
|
|
||||||
ctx.config.prefer_prelude,
|
|
||||||
)
|
|
||||||
.filter(|import| {
|
.filter(|import| {
|
||||||
!ctx.is_item_hidden(&import.item_to_import)
|
!ctx.is_item_hidden(&import.item_to_import)
|
||||||
&& !ctx.is_item_hidden(&import.original_item)
|
&& !ctx.is_item_hidden(&import.original_item)
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
mod format_like;
|
mod format_like;
|
||||||
|
|
||||||
use hir::ItemInNs;
|
use hir::{ImportPathConfig, ItemInNs};
|
||||||
use ide_db::{
|
use ide_db::{
|
||||||
documentation::{Documentation, HasDocs},
|
documentation::{Documentation, HasDocs},
|
||||||
imports::insert_use::ImportScope,
|
imports::insert_use::ImportScope,
|
||||||
|
@ -60,15 +60,17 @@ pub(crate) fn complete_postfix(
|
||||||
None => return,
|
None => return,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let cfg = ImportPathConfig {
|
||||||
|
prefer_no_std: ctx.config.prefer_no_std,
|
||||||
|
prefer_prelude: ctx.config.prefer_prelude,
|
||||||
|
};
|
||||||
|
|
||||||
if let Some(drop_trait) = ctx.famous_defs().core_ops_Drop() {
|
if let Some(drop_trait) = ctx.famous_defs().core_ops_Drop() {
|
||||||
if receiver_ty.impls_trait(ctx.db, drop_trait, &[]) {
|
if receiver_ty.impls_trait(ctx.db, drop_trait, &[]) {
|
||||||
if let Some(drop_fn) = ctx.famous_defs().core_mem_drop() {
|
if let Some(drop_fn) = ctx.famous_defs().core_mem_drop() {
|
||||||
if let Some(path) = ctx.module.find_path(
|
if let Some(path) =
|
||||||
ctx.db,
|
ctx.module.find_path(ctx.db, ItemInNs::Values(drop_fn.into()), cfg)
|
||||||
ItemInNs::Values(drop_fn.into()),
|
{
|
||||||
ctx.config.prefer_no_std,
|
|
||||||
ctx.config.prefer_prelude,
|
|
||||||
) {
|
|
||||||
cov_mark::hit!(postfix_drop_completion);
|
cov_mark::hit!(postfix_drop_completion);
|
||||||
let mut item = postfix_snippet(
|
let mut item = postfix_snippet(
|
||||||
"drop",
|
"drop",
|
||||||
|
|
|
@ -12,6 +12,7 @@ mod snippet;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests;
|
mod tests;
|
||||||
|
|
||||||
|
use hir::ImportPathConfig;
|
||||||
use ide_db::{
|
use ide_db::{
|
||||||
base_db::FilePosition,
|
base_db::FilePosition,
|
||||||
helpers::mod_path_to_ast,
|
helpers::mod_path_to_ast,
|
||||||
|
@ -251,6 +252,11 @@ pub fn resolve_completion_edits(
|
||||||
let new_ast = scope.clone_for_update();
|
let new_ast = scope.clone_for_update();
|
||||||
let mut import_insert = TextEdit::builder();
|
let mut import_insert = TextEdit::builder();
|
||||||
|
|
||||||
|
let cfg = ImportPathConfig {
|
||||||
|
prefer_no_std: config.prefer_no_std,
|
||||||
|
prefer_prelude: config.prefer_prelude,
|
||||||
|
};
|
||||||
|
|
||||||
imports.into_iter().for_each(|(full_import_path, imported_name)| {
|
imports.into_iter().for_each(|(full_import_path, imported_name)| {
|
||||||
let items_with_name = items_locator::items_with_name(
|
let items_with_name = items_locator::items_with_name(
|
||||||
&sema,
|
&sema,
|
||||||
|
@ -264,8 +270,7 @@ pub fn resolve_completion_edits(
|
||||||
db,
|
db,
|
||||||
candidate,
|
candidate,
|
||||||
config.insert_use.prefix_kind,
|
config.insert_use.prefix_kind,
|
||||||
config.prefer_no_std,
|
cfg,
|
||||||
config.prefer_prelude,
|
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.find(|mod_path| mod_path.display(db).to_string() == full_import_path);
|
.find(|mod_path| mod_path.display(db).to_string() == full_import_path);
|
||||||
|
|
|
@ -10,7 +10,7 @@ pub(crate) mod type_alias;
|
||||||
pub(crate) mod union_literal;
|
pub(crate) mod union_literal;
|
||||||
pub(crate) mod variant;
|
pub(crate) mod variant;
|
||||||
|
|
||||||
use hir::{AsAssocItem, HasAttrs, HirDisplay, ModuleDef, ScopeDef, Type};
|
use hir::{AsAssocItem, HasAttrs, HirDisplay, ImportPathConfig, ModuleDef, ScopeDef, Type};
|
||||||
use ide_db::{
|
use ide_db::{
|
||||||
documentation::{Documentation, HasDocs},
|
documentation::{Documentation, HasDocs},
|
||||||
helpers::item_name,
|
helpers::item_name,
|
||||||
|
@ -295,14 +295,12 @@ pub(crate) fn render_expr(
|
||||||
.unwrap_or_else(|| String::from("..."))
|
.unwrap_or_else(|| String::from("..."))
|
||||||
};
|
};
|
||||||
|
|
||||||
let label = expr
|
let cfg = ImportPathConfig {
|
||||||
.gen_source_code(
|
prefer_no_std: ctx.config.prefer_no_std,
|
||||||
&ctx.scope,
|
prefer_prelude: ctx.config.prefer_prelude,
|
||||||
&mut label_formatter,
|
};
|
||||||
ctx.config.prefer_no_std,
|
|
||||||
ctx.config.prefer_prelude,
|
let label = expr.gen_source_code(&ctx.scope, &mut label_formatter, cfg).ok()?;
|
||||||
)
|
|
||||||
.ok()?;
|
|
||||||
|
|
||||||
let source_range = match ctx.original_token.parent() {
|
let source_range = match ctx.original_token.parent() {
|
||||||
Some(node) => match node.ancestors().find_map(ast::Path::cast) {
|
Some(node) => match node.ancestors().find_map(ast::Path::cast) {
|
||||||
|
@ -314,16 +312,8 @@ pub(crate) fn render_expr(
|
||||||
|
|
||||||
let mut item = CompletionItem::new(CompletionItemKind::Expression, source_range, label);
|
let mut item = CompletionItem::new(CompletionItemKind::Expression, source_range, label);
|
||||||
|
|
||||||
let snippet = format!(
|
let snippet =
|
||||||
"{}$0",
|
format!("{}$0", expr.gen_source_code(&ctx.scope, &mut snippet_formatter, cfg).ok()?);
|
||||||
expr.gen_source_code(
|
|
||||||
&ctx.scope,
|
|
||||||
&mut snippet_formatter,
|
|
||||||
ctx.config.prefer_no_std,
|
|
||||||
ctx.config.prefer_prelude
|
|
||||||
)
|
|
||||||
.ok()?
|
|
||||||
);
|
|
||||||
let edit = TextEdit::replace(source_range, snippet);
|
let edit = TextEdit::replace(source_range, snippet);
|
||||||
item.snippet_edit(ctx.config.snippet_cap?, edit);
|
item.snippet_edit(ctx.config.snippet_cap?, edit);
|
||||||
item.documentation(Documentation::new(String::from("Autogenerated expression by term search")));
|
item.documentation(Documentation::new(String::from("Autogenerated expression by term search")));
|
||||||
|
@ -333,12 +323,7 @@ pub(crate) fn render_expr(
|
||||||
});
|
});
|
||||||
for trait_ in expr.traits_used(ctx.db) {
|
for trait_ in expr.traits_used(ctx.db) {
|
||||||
let trait_item = hir::ItemInNs::from(hir::ModuleDef::from(trait_));
|
let trait_item = hir::ItemInNs::from(hir::ModuleDef::from(trait_));
|
||||||
let Some(path) = ctx.module.find_path(
|
let Some(path) = ctx.module.find_path(ctx.db, trait_item, cfg) else {
|
||||||
ctx.db,
|
|
||||||
trait_item,
|
|
||||||
ctx.config.prefer_no_std,
|
|
||||||
ctx.config.prefer_prelude,
|
|
||||||
) else {
|
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -100,6 +100,7 @@
|
||||||
// }
|
// }
|
||||||
// ----
|
// ----
|
||||||
|
|
||||||
|
use hir::ImportPathConfig;
|
||||||
use ide_db::imports::import_assets::LocatedImport;
|
use ide_db::imports::import_assets::LocatedImport;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use syntax::{ast, AstNode, GreenNode, SyntaxNode};
|
use syntax::{ast, AstNode, GreenNode, SyntaxNode};
|
||||||
|
@ -168,6 +169,11 @@ impl Snippet {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn import_edits(ctx: &CompletionContext<'_>, requires: &[GreenNode]) -> Option<Vec<LocatedImport>> {
|
fn import_edits(ctx: &CompletionContext<'_>, requires: &[GreenNode]) -> Option<Vec<LocatedImport>> {
|
||||||
|
let import_cfg = ImportPathConfig {
|
||||||
|
prefer_no_std: ctx.config.prefer_no_std,
|
||||||
|
prefer_prelude: ctx.config.prefer_prelude,
|
||||||
|
};
|
||||||
|
|
||||||
let resolve = |import: &GreenNode| {
|
let resolve = |import: &GreenNode| {
|
||||||
let path = ast::Path::cast(SyntaxNode::new_root(import.clone()))?;
|
let path = ast::Path::cast(SyntaxNode::new_root(import.clone()))?;
|
||||||
let item = match ctx.scope.speculative_resolve(&path)? {
|
let item = match ctx.scope.speculative_resolve(&path)? {
|
||||||
|
@ -178,8 +184,7 @@ fn import_edits(ctx: &CompletionContext<'_>, requires: &[GreenNode]) -> Option<V
|
||||||
ctx.db,
|
ctx.db,
|
||||||
item,
|
item,
|
||||||
ctx.config.insert_use.prefix_kind,
|
ctx.config.insert_use.prefix_kind,
|
||||||
ctx.config.prefer_no_std,
|
import_cfg,
|
||||||
ctx.config.prefer_prelude,
|
|
||||||
)?;
|
)?;
|
||||||
Some((path.len() > 1).then(|| LocatedImport::new(path.clone(), item, item)))
|
Some((path.len() > 1).then(|| LocatedImport::new(path.clone(), item, item)))
|
||||||
};
|
};
|
||||||
|
|
|
@ -66,11 +66,10 @@ pub(crate) const TEST_CONFIG: CompletionConfig = CompletionConfig {
|
||||||
enable_self_on_the_fly: true,
|
enable_self_on_the_fly: true,
|
||||||
enable_private_editable: false,
|
enable_private_editable: false,
|
||||||
enable_term_search: true,
|
enable_term_search: true,
|
||||||
|
term_search_fuel: 200,
|
||||||
full_function_signatures: false,
|
full_function_signatures: false,
|
||||||
callable: Some(CallableSnippets::FillArguments),
|
callable: Some(CallableSnippets::FillArguments),
|
||||||
snippet_cap: SnippetCap::new(true),
|
snippet_cap: SnippetCap::new(true),
|
||||||
prefer_no_std: false,
|
|
||||||
prefer_prelude: true,
|
|
||||||
insert_use: InsertUseConfig {
|
insert_use: InsertUseConfig {
|
||||||
granularity: ImportGranularity::Crate,
|
granularity: ImportGranularity::Crate,
|
||||||
prefix_kind: PrefixKind::Plain,
|
prefix_kind: PrefixKind::Plain,
|
||||||
|
@ -78,9 +77,10 @@ pub(crate) const TEST_CONFIG: CompletionConfig = CompletionConfig {
|
||||||
group: true,
|
group: true,
|
||||||
skip_glob_imports: true,
|
skip_glob_imports: true,
|
||||||
},
|
},
|
||||||
|
prefer_no_std: false,
|
||||||
|
prefer_prelude: true,
|
||||||
snippets: Vec::new(),
|
snippets: Vec::new(),
|
||||||
limit: None,
|
limit: None,
|
||||||
term_search_fuel: 200,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub(crate) fn completion_list(ra_fixture: &str) -> String {
|
pub(crate) fn completion_list(ra_fixture: &str) -> String {
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
//! Look up accessible paths for items.
|
//! Look up accessible paths for items.
|
||||||
|
|
||||||
use hir::{
|
use hir::{
|
||||||
db::HirDatabase, AsAssocItem, AssocItem, AssocItemContainer, Crate, HasCrate, ItemInNs,
|
db::HirDatabase, AsAssocItem, AssocItem, AssocItemContainer, Crate, HasCrate, ImportPathConfig,
|
||||||
ModPath, Module, ModuleDef, Name, PathResolution, PrefixKind, ScopeDef, Semantics,
|
ItemInNs, ModPath, Module, ModuleDef, Name, PathResolution, PrefixKind, ScopeDef, Semantics,
|
||||||
SemanticsScope, Trait, Type,
|
SemanticsScope, Trait, Type,
|
||||||
};
|
};
|
||||||
use itertools::{EitherOrBoth, Itertools};
|
use itertools::{EitherOrBoth, Itertools};
|
||||||
|
@ -205,24 +205,22 @@ impl ImportAssets {
|
||||||
pub fn search_for_imports(
|
pub fn search_for_imports(
|
||||||
&self,
|
&self,
|
||||||
sema: &Semantics<'_, RootDatabase>,
|
sema: &Semantics<'_, RootDatabase>,
|
||||||
|
cfg: ImportPathConfig,
|
||||||
prefix_kind: PrefixKind,
|
prefix_kind: PrefixKind,
|
||||||
prefer_no_std: bool,
|
|
||||||
prefer_prelude: bool,
|
|
||||||
) -> impl Iterator<Item = LocatedImport> {
|
) -> impl Iterator<Item = LocatedImport> {
|
||||||
let _p = tracing::span!(tracing::Level::INFO, "ImportAssets::search_for_imports").entered();
|
let _p = tracing::span!(tracing::Level::INFO, "ImportAssets::search_for_imports").entered();
|
||||||
self.search_for(sema, Some(prefix_kind), prefer_no_std, prefer_prelude)
|
self.search_for(sema, Some(prefix_kind), cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This may return non-absolute paths if a part of the returned path is already imported into scope.
|
/// This may return non-absolute paths if a part of the returned path is already imported into scope.
|
||||||
pub fn search_for_relative_paths(
|
pub fn search_for_relative_paths(
|
||||||
&self,
|
&self,
|
||||||
sema: &Semantics<'_, RootDatabase>,
|
sema: &Semantics<'_, RootDatabase>,
|
||||||
prefer_no_std: bool,
|
cfg: ImportPathConfig,
|
||||||
prefer_prelude: bool,
|
|
||||||
) -> impl Iterator<Item = LocatedImport> {
|
) -> impl Iterator<Item = LocatedImport> {
|
||||||
let _p = tracing::span!(tracing::Level::INFO, "ImportAssets::search_for_relative_paths")
|
let _p = tracing::span!(tracing::Level::INFO, "ImportAssets::search_for_relative_paths")
|
||||||
.entered();
|
.entered();
|
||||||
self.search_for(sema, None, prefer_no_std, prefer_prelude)
|
self.search_for(sema, None, cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Requires imports to by prefix instead of fuzzily.
|
/// Requires imports to by prefix instead of fuzzily.
|
||||||
|
@ -259,8 +257,7 @@ impl ImportAssets {
|
||||||
&self,
|
&self,
|
||||||
sema: &Semantics<'_, RootDatabase>,
|
sema: &Semantics<'_, RootDatabase>,
|
||||||
prefixed: Option<PrefixKind>,
|
prefixed: Option<PrefixKind>,
|
||||||
prefer_no_std: bool,
|
cfg: ImportPathConfig,
|
||||||
prefer_prelude: bool,
|
|
||||||
) -> impl Iterator<Item = LocatedImport> {
|
) -> impl Iterator<Item = LocatedImport> {
|
||||||
let _p = tracing::span!(tracing::Level::INFO, "ImportAssets::search_for").entered();
|
let _p = tracing::span!(tracing::Level::INFO, "ImportAssets::search_for").entered();
|
||||||
|
|
||||||
|
@ -277,8 +274,7 @@ impl ImportAssets {
|
||||||
item_for_path_search(sema.db, item)?,
|
item_for_path_search(sema.db, item)?,
|
||||||
&self.module_with_candidate,
|
&self.module_with_candidate,
|
||||||
prefixed,
|
prefixed,
|
||||||
prefer_no_std,
|
cfg,
|
||||||
prefer_prelude,
|
|
||||||
)
|
)
|
||||||
.filter(|path| path.len() > 1)
|
.filter(|path| path.len() > 1)
|
||||||
};
|
};
|
||||||
|
@ -634,19 +630,12 @@ fn get_mod_path(
|
||||||
item_to_search: ItemInNs,
|
item_to_search: ItemInNs,
|
||||||
module_with_candidate: &Module,
|
module_with_candidate: &Module,
|
||||||
prefixed: Option<PrefixKind>,
|
prefixed: Option<PrefixKind>,
|
||||||
prefer_no_std: bool,
|
cfg: ImportPathConfig,
|
||||||
prefer_prelude: bool,
|
|
||||||
) -> Option<ModPath> {
|
) -> Option<ModPath> {
|
||||||
if let Some(prefix_kind) = prefixed {
|
if let Some(prefix_kind) = prefixed {
|
||||||
module_with_candidate.find_use_path(
|
module_with_candidate.find_use_path(db, item_to_search, prefix_kind, cfg)
|
||||||
db,
|
|
||||||
item_to_search,
|
|
||||||
prefix_kind,
|
|
||||||
prefer_no_std,
|
|
||||||
prefer_prelude,
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
module_with_candidate.find_path(db, item_to_search, prefer_no_std, prefer_prelude)
|
module_with_candidate.find_path(db, item_to_search, cfg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
use crate::helpers::mod_path_to_ast;
|
use crate::helpers::mod_path_to_ast;
|
||||||
use either::Either;
|
use either::Either;
|
||||||
use hir::{AsAssocItem, HirDisplay, ModuleDef, SemanticsScope};
|
use hir::{AsAssocItem, HirDisplay, ImportPathConfig, ModuleDef, SemanticsScope};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
use syntax::{
|
use syntax::{
|
||||||
|
@ -308,11 +308,12 @@ impl Ctx<'_> {
|
||||||
parent.segment()?.name_ref()?,
|
parent.segment()?.name_ref()?,
|
||||||
)
|
)
|
||||||
.and_then(|trait_ref| {
|
.and_then(|trait_ref| {
|
||||||
|
let cfg =
|
||||||
|
ImportPathConfig { prefer_no_std: false, prefer_prelude: true };
|
||||||
let found_path = self.target_module.find_path(
|
let found_path = self.target_module.find_path(
|
||||||
self.source_scope.db.upcast(),
|
self.source_scope.db.upcast(),
|
||||||
hir::ModuleDef::Trait(trait_ref),
|
hir::ModuleDef::Trait(trait_ref),
|
||||||
false,
|
cfg,
|
||||||
true,
|
|
||||||
)?;
|
)?;
|
||||||
match make::ty_path(mod_path_to_ast(&found_path)) {
|
match make::ty_path(mod_path_to_ast(&found_path)) {
|
||||||
ast::Type::PathType(path_ty) => Some(path_ty),
|
ast::Type::PathType(path_ty) => Some(path_ty),
|
||||||
|
@ -347,12 +348,9 @@ impl Ctx<'_> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let found_path = self.target_module.find_path(
|
let cfg = ImportPathConfig { prefer_no_std: false, prefer_prelude: true };
|
||||||
self.source_scope.db.upcast(),
|
let found_path =
|
||||||
def,
|
self.target_module.find_path(self.source_scope.db.upcast(), def, cfg)?;
|
||||||
false,
|
|
||||||
true,
|
|
||||||
)?;
|
|
||||||
let res = mod_path_to_ast(&found_path).clone_for_update();
|
let res = mod_path_to_ast(&found_path).clone_for_update();
|
||||||
if let Some(args) = path.segment().and_then(|it| it.generic_arg_list()) {
|
if let Some(args) = path.segment().and_then(|it| it.generic_arg_list()) {
|
||||||
if let Some(segment) = res.segment() {
|
if let Some(segment) = res.segment() {
|
||||||
|
@ -385,11 +383,11 @@ impl Ctx<'_> {
|
||||||
|
|
||||||
if let Some(adt) = ty.as_adt() {
|
if let Some(adt) = ty.as_adt() {
|
||||||
if let ast::Type::PathType(path_ty) = &ast_ty {
|
if let ast::Type::PathType(path_ty) = &ast_ty {
|
||||||
|
let cfg = ImportPathConfig { prefer_no_std: false, prefer_prelude: true };
|
||||||
let found_path = self.target_module.find_path(
|
let found_path = self.target_module.find_path(
|
||||||
self.source_scope.db.upcast(),
|
self.source_scope.db.upcast(),
|
||||||
ModuleDef::from(adt),
|
ModuleDef::from(adt),
|
||||||
false,
|
cfg,
|
||||||
true,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
if let Some(qual) = mod_path_to_ast(&found_path).qualifier() {
|
if let Some(qual) = mod_path_to_ast(&found_path).qualifier() {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
//! This diagnostic provides an assist for creating a struct definition from a JSON
|
//! This diagnostic provides an assist for creating a struct definition from a JSON
|
||||||
//! example.
|
//! example.
|
||||||
|
|
||||||
use hir::{PathResolution, Semantics};
|
use hir::{ImportPathConfig, PathResolution, Semantics};
|
||||||
use ide_db::{
|
use ide_db::{
|
||||||
base_db::{FileId, FileRange},
|
base_db::{FileId, FileRange},
|
||||||
helpers::mod_path_to_ast,
|
helpers::mod_path_to_ast,
|
||||||
|
@ -142,14 +142,19 @@ pub(crate) fn json_in_items(
|
||||||
ImportScope::Block(it) => ImportScope::Block(scb.make_mut(it)),
|
ImportScope::Block(it) => ImportScope::Block(scb.make_mut(it)),
|
||||||
};
|
};
|
||||||
let current_module = semantics_scope.module();
|
let current_module = semantics_scope.module();
|
||||||
|
|
||||||
|
let cfg = ImportPathConfig {
|
||||||
|
prefer_no_std: config.prefer_no_std,
|
||||||
|
prefer_prelude: config.prefer_prelude,
|
||||||
|
};
|
||||||
|
|
||||||
if !scope_has("Serialize") {
|
if !scope_has("Serialize") {
|
||||||
if let Some(PathResolution::Def(it)) = serialize_resolved {
|
if let Some(PathResolution::Def(it)) = serialize_resolved {
|
||||||
if let Some(it) = current_module.find_use_path(
|
if let Some(it) = current_module.find_use_path(
|
||||||
sema.db,
|
sema.db,
|
||||||
it,
|
it,
|
||||||
config.insert_use.prefix_kind,
|
config.insert_use.prefix_kind,
|
||||||
config.prefer_no_std,
|
cfg,
|
||||||
config.prefer_prelude,
|
|
||||||
) {
|
) {
|
||||||
insert_use(&scope, mod_path_to_ast(&it), &config.insert_use);
|
insert_use(&scope, mod_path_to_ast(&it), &config.insert_use);
|
||||||
}
|
}
|
||||||
|
@ -161,8 +166,7 @@ pub(crate) fn json_in_items(
|
||||||
sema.db,
|
sema.db,
|
||||||
it,
|
it,
|
||||||
config.insert_use.prefix_kind,
|
config.insert_use.prefix_kind,
|
||||||
config.prefer_no_std,
|
cfg,
|
||||||
config.prefer_prelude,
|
|
||||||
) {
|
) {
|
||||||
insert_use(&scope, mod_path_to_ast(&it), &config.insert_use);
|
insert_use(&scope, mod_path_to_ast(&it), &config.insert_use);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use either::Either;
|
use either::Either;
|
||||||
use hir::{
|
use hir::{
|
||||||
db::{ExpandDatabase, HirDatabase},
|
db::{ExpandDatabase, HirDatabase},
|
||||||
known, AssocItem, HirDisplay, HirFileIdExt, InFile, Type,
|
known, AssocItem, HirDisplay, HirFileIdExt, ImportPathConfig, InFile, Type,
|
||||||
};
|
};
|
||||||
use ide_db::{
|
use ide_db::{
|
||||||
assists::Assist, famous_defs::FamousDefs, imports::import_assets::item_for_path_search,
|
assists::Assist, famous_defs::FamousDefs, imports::import_assets::item_for_path_search,
|
||||||
|
@ -125,8 +125,10 @@ fn fixes(ctx: &DiagnosticsContext<'_>, d: &hir::MissingFields) -> Option<Vec<Ass
|
||||||
let type_path = current_module?.find_path(
|
let type_path = current_module?.find_path(
|
||||||
ctx.sema.db,
|
ctx.sema.db,
|
||||||
item_for_path_search(ctx.sema.db, item_in_ns)?,
|
item_for_path_search(ctx.sema.db, item_in_ns)?,
|
||||||
ctx.config.prefer_no_std,
|
ImportPathConfig {
|
||||||
ctx.config.prefer_prelude,
|
prefer_no_std: ctx.config.prefer_no_std,
|
||||||
|
prefer_prelude: ctx.config.prefer_prelude,
|
||||||
|
},
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
use_trivial_constructor(
|
use_trivial_constructor(
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use hir::{
|
use hir::{
|
||||||
db::ExpandDatabase,
|
db::ExpandDatabase,
|
||||||
term_search::{term_search, TermSearchConfig, TermSearchCtx},
|
term_search::{term_search, TermSearchConfig, TermSearchCtx},
|
||||||
ClosureStyle, HirDisplay,
|
ClosureStyle, HirDisplay, ImportPathConfig,
|
||||||
};
|
};
|
||||||
use ide_db::{
|
use ide_db::{
|
||||||
assists::{Assist, AssistId, AssistKind, GroupLabel},
|
assists::{Assist, AssistId, AssistKind, GroupLabel},
|
||||||
|
@ -59,8 +59,10 @@ fn fixes(ctx: &DiagnosticsContext<'_>, d: &hir::TypedHole) -> Option<Vec<Assist>
|
||||||
path.gen_source_code(
|
path.gen_source_code(
|
||||||
&scope,
|
&scope,
|
||||||
&mut formatter,
|
&mut formatter,
|
||||||
ctx.config.prefer_no_std,
|
ImportPathConfig {
|
||||||
ctx.config.prefer_prelude,
|
prefer_no_std: ctx.config.prefer_no_std,
|
||||||
|
prefer_prelude: ctx.config.prefer_prelude,
|
||||||
|
},
|
||||||
)
|
)
|
||||||
.ok()
|
.ok()
|
||||||
})
|
})
|
||||||
|
|
|
@ -6,7 +6,7 @@ use crate::{
|
||||||
resolving::{ResolvedPattern, ResolvedRule, UfcsCallInfo},
|
resolving::{ResolvedPattern, ResolvedRule, UfcsCallInfo},
|
||||||
SsrMatches,
|
SsrMatches,
|
||||||
};
|
};
|
||||||
use hir::Semantics;
|
use hir::{ImportPathConfig, Semantics};
|
||||||
use ide_db::{base_db::FileRange, FxHashMap};
|
use ide_db::{base_db::FileRange, FxHashMap};
|
||||||
use std::{cell::Cell, iter::Peekable};
|
use std::{cell::Cell, iter::Peekable};
|
||||||
use syntax::{
|
use syntax::{
|
||||||
|
@ -663,10 +663,10 @@ impl Match {
|
||||||
.module();
|
.module();
|
||||||
for (path, resolved_path) in &template.resolved_paths {
|
for (path, resolved_path) in &template.resolved_paths {
|
||||||
if let hir::PathResolution::Def(module_def) = resolved_path.resolution {
|
if let hir::PathResolution::Def(module_def) = resolved_path.resolution {
|
||||||
let mod_path =
|
let cfg = ImportPathConfig { prefer_no_std: false, prefer_prelude: true };
|
||||||
module.find_path(sema.db, module_def, false, true).ok_or_else(|| {
|
let mod_path = module.find_path(sema.db, module_def, cfg).ok_or_else(|| {
|
||||||
match_error!("Failed to render template path `{}` at match location")
|
match_error!("Failed to render template path `{}` at match location")
|
||||||
})?;
|
})?;
|
||||||
self.rendered_template_paths.insert(path.clone(), mod_path);
|
self.rendered_template_paths.insert(path.clone(), mod_path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,8 @@ use std::{
|
||||||
|
|
||||||
use hir::{
|
use hir::{
|
||||||
db::{DefDatabase, ExpandDatabase, HirDatabase},
|
db::{DefDatabase, ExpandDatabase, HirDatabase},
|
||||||
Adt, AssocItem, Crate, DefWithBody, HasSource, HirDisplay, HirFileIdExt, ModuleDef, Name,
|
Adt, AssocItem, Crate, DefWithBody, HasSource, HirDisplay, HirFileIdExt, ImportPathConfig,
|
||||||
|
ModuleDef, Name,
|
||||||
};
|
};
|
||||||
use hir_def::{
|
use hir_def::{
|
||||||
body::{BodySourceMap, SyntheticSyntax},
|
body::{BodySourceMap, SyntheticSyntax},
|
||||||
|
@ -438,8 +439,13 @@ impl flags::AnalysisStats {
|
||||||
let mut formatter = |_: &hir::Type| todo.clone();
|
let mut formatter = |_: &hir::Type| todo.clone();
|
||||||
let mut syntax_hit_found = false;
|
let mut syntax_hit_found = false;
|
||||||
for term in found_terms {
|
for term in found_terms {
|
||||||
let generated =
|
let generated = term
|
||||||
term.gen_source_code(&scope, &mut formatter, false, true).unwrap();
|
.gen_source_code(
|
||||||
|
&scope,
|
||||||
|
&mut formatter,
|
||||||
|
ImportPathConfig { prefer_no_std: false, prefer_prelude: true },
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
syntax_hit_found |= trim(&original_text) == trim(&generated);
|
syntax_hit_found |= trim(&original_text) == trim(&generated);
|
||||||
|
|
||||||
// Validate if type-checks
|
// Validate if type-checks
|
||||||
|
|
|
@ -1031,6 +1031,8 @@ impl Config {
|
||||||
&& completion_item_edit_resolve(&self.caps),
|
&& completion_item_edit_resolve(&self.caps),
|
||||||
enable_self_on_the_fly: self.completion_autoself_enable(source_root).to_owned(),
|
enable_self_on_the_fly: self.completion_autoself_enable(source_root).to_owned(),
|
||||||
enable_private_editable: self.completion_privateEditable_enable(source_root).to_owned(),
|
enable_private_editable: self.completion_privateEditable_enable(source_root).to_owned(),
|
||||||
|
enable_term_search: self.completion_termSearch_enable(source_root).to_owned(),
|
||||||
|
term_search_fuel: self.completion_termSearch_fuel(source_root).to_owned() as u64,
|
||||||
full_function_signatures: self
|
full_function_signatures: self
|
||||||
.completion_fullFunctionSignatures_enable(source_root)
|
.completion_fullFunctionSignatures_enable(source_root)
|
||||||
.to_owned(),
|
.to_owned(),
|
||||||
|
@ -1039,8 +1041,6 @@ impl Config {
|
||||||
CallableCompletionDef::AddParentheses => Some(CallableSnippets::AddParentheses),
|
CallableCompletionDef::AddParentheses => Some(CallableSnippets::AddParentheses),
|
||||||
CallableCompletionDef::None => None,
|
CallableCompletionDef::None => None,
|
||||||
},
|
},
|
||||||
insert_use: self.insert_use_config(source_root),
|
|
||||||
prefer_no_std: self.imports_preferNoStd(source_root).to_owned(),
|
|
||||||
snippet_cap: SnippetCap::new(try_or_def!(
|
snippet_cap: SnippetCap::new(try_or_def!(
|
||||||
self.caps
|
self.caps
|
||||||
.text_document
|
.text_document
|
||||||
|
@ -1051,11 +1051,11 @@ impl Config {
|
||||||
.as_ref()?
|
.as_ref()?
|
||||||
.snippet_support?
|
.snippet_support?
|
||||||
)),
|
)),
|
||||||
|
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(),
|
||||||
snippets: self.snippets.clone().to_vec(),
|
snippets: self.snippets.clone().to_vec(),
|
||||||
limit: self.completion_limit(source_root).to_owned(),
|
limit: self.completion_limit(source_root).to_owned(),
|
||||||
enable_term_search: self.completion_termSearch_enable(source_root).to_owned(),
|
|
||||||
term_search_fuel: self.completion_termSearch_fuel(source_root).to_owned() as u64,
|
|
||||||
prefer_prelude: self.imports_preferPrelude(source_root).to_owned(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -139,6 +139,7 @@ fn integrated_completion_benchmark() {
|
||||||
enable_self_on_the_fly: true,
|
enable_self_on_the_fly: true,
|
||||||
enable_private_editable: true,
|
enable_private_editable: true,
|
||||||
enable_term_search: true,
|
enable_term_search: true,
|
||||||
|
term_search_fuel: 200,
|
||||||
full_function_signatures: false,
|
full_function_signatures: false,
|
||||||
callable: Some(CallableSnippets::FillArguments),
|
callable: Some(CallableSnippets::FillArguments),
|
||||||
snippet_cap: SnippetCap::new(true),
|
snippet_cap: SnippetCap::new(true),
|
||||||
|
@ -149,11 +150,10 @@ fn integrated_completion_benchmark() {
|
||||||
group: true,
|
group: true,
|
||||||
skip_glob_imports: true,
|
skip_glob_imports: true,
|
||||||
},
|
},
|
||||||
snippets: Vec::new(),
|
|
||||||
prefer_no_std: false,
|
prefer_no_std: false,
|
||||||
prefer_prelude: true,
|
prefer_prelude: true,
|
||||||
|
snippets: Vec::new(),
|
||||||
limit: None,
|
limit: None,
|
||||||
term_search_fuel: 200,
|
|
||||||
};
|
};
|
||||||
let position =
|
let position =
|
||||||
FilePosition { file_id, offset: TextSize::try_from(completion_offset).unwrap() };
|
FilePosition { file_id, offset: TextSize::try_from(completion_offset).unwrap() };
|
||||||
|
@ -184,6 +184,7 @@ fn integrated_completion_benchmark() {
|
||||||
enable_self_on_the_fly: true,
|
enable_self_on_the_fly: true,
|
||||||
enable_private_editable: true,
|
enable_private_editable: true,
|
||||||
enable_term_search: true,
|
enable_term_search: true,
|
||||||
|
term_search_fuel: 200,
|
||||||
full_function_signatures: false,
|
full_function_signatures: false,
|
||||||
callable: Some(CallableSnippets::FillArguments),
|
callable: Some(CallableSnippets::FillArguments),
|
||||||
snippet_cap: SnippetCap::new(true),
|
snippet_cap: SnippetCap::new(true),
|
||||||
|
@ -194,11 +195,10 @@ fn integrated_completion_benchmark() {
|
||||||
group: true,
|
group: true,
|
||||||
skip_glob_imports: true,
|
skip_glob_imports: true,
|
||||||
},
|
},
|
||||||
snippets: Vec::new(),
|
|
||||||
prefer_no_std: false,
|
prefer_no_std: false,
|
||||||
prefer_prelude: true,
|
prefer_prelude: true,
|
||||||
|
snippets: Vec::new(),
|
||||||
limit: None,
|
limit: None,
|
||||||
term_search_fuel: 200,
|
|
||||||
};
|
};
|
||||||
let position =
|
let position =
|
||||||
FilePosition { file_id, offset: TextSize::try_from(completion_offset).unwrap() };
|
FilePosition { file_id, offset: TextSize::try_from(completion_offset).unwrap() };
|
||||||
|
@ -227,6 +227,7 @@ fn integrated_completion_benchmark() {
|
||||||
enable_self_on_the_fly: true,
|
enable_self_on_the_fly: true,
|
||||||
enable_private_editable: true,
|
enable_private_editable: true,
|
||||||
enable_term_search: true,
|
enable_term_search: true,
|
||||||
|
term_search_fuel: 200,
|
||||||
full_function_signatures: false,
|
full_function_signatures: false,
|
||||||
callable: Some(CallableSnippets::FillArguments),
|
callable: Some(CallableSnippets::FillArguments),
|
||||||
snippet_cap: SnippetCap::new(true),
|
snippet_cap: SnippetCap::new(true),
|
||||||
|
@ -237,11 +238,10 @@ fn integrated_completion_benchmark() {
|
||||||
group: true,
|
group: true,
|
||||||
skip_glob_imports: true,
|
skip_glob_imports: true,
|
||||||
},
|
},
|
||||||
snippets: Vec::new(),
|
|
||||||
prefer_no_std: false,
|
prefer_no_std: false,
|
||||||
prefer_prelude: true,
|
prefer_prelude: true,
|
||||||
|
snippets: Vec::new(),
|
||||||
limit: None,
|
limit: None,
|
||||||
term_search_fuel: 200,
|
|
||||||
};
|
};
|
||||||
let position =
|
let position =
|
||||||
FilePosition { file_id, offset: TextSize::try_from(completion_offset).unwrap() };
|
FilePosition { file_id, offset: TextSize::try_from(completion_offset).unwrap() };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue