mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
Simplify
This commit is contained in:
parent
b75301cec8
commit
3a7dcf91c4
3 changed files with 11 additions and 16 deletions
|
@ -1,9 +1,6 @@
|
||||||
//! An algorithm to find a path to refer to a certain item.
|
//! An algorithm to find a path to refer to a certain item.
|
||||||
|
|
||||||
use std::{
|
use std::{cmp::Ordering, iter};
|
||||||
cmp::Ordering,
|
|
||||||
iter::{self, once},
|
|
||||||
};
|
|
||||||
|
|
||||||
use hir_expand::{
|
use hir_expand::{
|
||||||
name::{known, AsName, Name},
|
name::{known, AsName, Name},
|
||||||
|
@ -85,7 +82,7 @@ struct FindPathCtx<'db> {
|
||||||
fn find_path_inner(ctx: FindPathCtx<'_>, item: ItemInNs, from: ModuleId) -> Option<ModPath> {
|
fn find_path_inner(ctx: FindPathCtx<'_>, item: ItemInNs, from: ModuleId) -> Option<ModPath> {
|
||||||
// - if the item is a builtin, it's in scope
|
// - if the item is a builtin, it's in scope
|
||||||
if let ItemInNs::Types(ModuleDefId::BuiltinType(builtin)) = item {
|
if let ItemInNs::Types(ModuleDefId::BuiltinType(builtin)) = item {
|
||||||
return Some(ModPath::from_segments(PathKind::Plain, once(builtin.as_name())));
|
return Some(ModPath::from_segments(PathKind::Plain, iter::once(builtin.as_name())));
|
||||||
}
|
}
|
||||||
|
|
||||||
let def_map = from.def_map(ctx.db);
|
let def_map = from.def_map(ctx.db);
|
||||||
|
@ -124,7 +121,7 @@ fn find_path_inner(ctx: FindPathCtx<'_>, item: ItemInNs, from: ModuleId) -> Opti
|
||||||
// - if the item is already in scope, return the name under which it is
|
// - if the item is already in scope, return the name under which it is
|
||||||
let scope_name = find_in_scope(ctx.db, &def_map, from, item, ctx.ignore_local_imports);
|
let scope_name = find_in_scope(ctx.db, &def_map, from, item, ctx.ignore_local_imports);
|
||||||
if let Some(scope_name) = scope_name {
|
if let Some(scope_name) = scope_name {
|
||||||
return Some(ModPath::from_segments(prefix.path_kind(), Some(scope_name)));
|
return Some(ModPath::from_segments(prefix.path_kind(), iter::once(scope_name)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,7 +206,7 @@ fn find_path_for_module(
|
||||||
} else {
|
} else {
|
||||||
PathKind::Plain
|
PathKind::Plain
|
||||||
};
|
};
|
||||||
return Some((ModPath::from_segments(kind, once(name.clone())), Stable));
|
return Some((ModPath::from_segments(kind, iter::once(name.clone())), Stable));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let prefix = if module_id.is_within_block() { PrefixKind::Plain } else { ctx.prefix };
|
let prefix = if module_id.is_within_block() { PrefixKind::Plain } else { ctx.prefix };
|
||||||
|
@ -227,7 +224,10 @@ fn find_path_for_module(
|
||||||
);
|
);
|
||||||
if let Some(scope_name) = scope_name {
|
if let Some(scope_name) = scope_name {
|
||||||
// - if the item is already in scope, return the name under which it is
|
// - if the item is already in scope, return the name under which it is
|
||||||
return Some((ModPath::from_segments(prefix.path_kind(), once(scope_name)), Stable));
|
return Some((
|
||||||
|
ModPath::from_segments(prefix.path_kind(), iter::once(scope_name)),
|
||||||
|
Stable,
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -301,7 +301,7 @@ fn find_in_prelude(
|
||||||
});
|
});
|
||||||
|
|
||||||
if found_and_same_def.unwrap_or(true) {
|
if found_and_same_def.unwrap_or(true) {
|
||||||
Some(ModPath::from_segments(PathKind::Plain, once(name.clone())))
|
Some(ModPath::from_segments(PathKind::Plain, iter::once(name.clone())))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
|
@ -1001,7 +1001,7 @@ impl HirDisplay for Ty {
|
||||||
ItemInNs::Types((*def_id).into()),
|
ItemInNs::Types((*def_id).into()),
|
||||||
module_id,
|
module_id,
|
||||||
PrefixKind::Plain,
|
PrefixKind::Plain,
|
||||||
true,
|
false,
|
||||||
ImportPathConfig { prefer_no_std: false, prefer_prelude: true },
|
ImportPathConfig { prefer_no_std: false, prefer_prelude: true },
|
||||||
) {
|
) {
|
||||||
write!(f, "{}", path.display(f.db.upcast()))?;
|
write!(f, "{}", path.display(f.db.upcast()))?;
|
||||||
|
|
|
@ -266,12 +266,7 @@ pub fn resolve_completion_edits(
|
||||||
);
|
);
|
||||||
let import = items_with_name
|
let import = items_with_name
|
||||||
.filter_map(|candidate| {
|
.filter_map(|candidate| {
|
||||||
current_module.find_use_path(
|
current_module.find_use_path(db, candidate, config.insert_use.prefix_kind, cfg)
|
||||||
db,
|
|
||||||
candidate,
|
|
||||||
config.insert_use.prefix_kind,
|
|
||||||
cfg,
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
.find(|mod_path| mod_path.display(db).to_string() == full_import_path);
|
.find(|mod_path| mod_path.display(db).to_string() == full_import_path);
|
||||||
if let Some(import_path) = import {
|
if let Some(import_path) = import {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue