complete_import: add new import resolver infrastructure with some hardcoded importable name.

Changes complete_scope to support that.
This commit is contained in:
Andrea Pretto
2019-04-15 16:11:32 +02:00
parent cf0eff2e33
commit 9144214958
6 changed files with 155 additions and 11 deletions

View File

@@ -3,6 +3,8 @@ use std::sync::Arc;
use rustc_hash::FxHashMap;
use ra_syntax::SmolStr;
use crate::{
ModuleDef,
code_model_api::Crate,
@@ -12,8 +14,12 @@ use crate::{
generics::GenericParams,
expr::{scope::{ExprScopes, ScopeId}, PatId},
impl_block::ImplBlock,
<<<<<<< HEAD
path::Path,
Trait
=======
path::Path, Trait,
>>>>>>> complete_import: add new import resolver infrastructure with some hardcoded importable name.
};
#[derive(Debug, Clone, Default)]
@@ -21,6 +27,12 @@ pub(crate) struct Resolver {
scopes: Vec<Scope>,
}
#[derive(Debug, Clone, Default)]
pub(crate) struct ImportResolver {
// todo: use fst crate or something like that
dummy_names: Vec<(SmolStr, Vec<SmolStr>)>,
}
// FIXME how to store these best
#[derive(Debug, Clone)]
pub(crate) struct ModuleItemMap {
@@ -309,3 +321,56 @@ impl Scope {
}
}
}
impl ImportResolver {
pub(crate) fn new() -> Self {
let dummy_names = vec![
(SmolStr::new("fmt"), vec![SmolStr::new("std"), SmolStr::new("fmt")]),
(SmolStr::new("io"), vec![SmolStr::new("std"), SmolStr::new("io")]),
(SmolStr::new("iter"), vec![SmolStr::new("std"), SmolStr::new("iter")]),
(SmolStr::new("hash"), vec![SmolStr::new("std"), SmolStr::new("hash")]),
(
SmolStr::new("Debug"),
vec![SmolStr::new("std"), SmolStr::new("fmt"), SmolStr::new("Debug")],
),
(
SmolStr::new("Display"),
vec![SmolStr::new("std"), SmolStr::new("fmt"), SmolStr::new("Display")],
),
(
SmolStr::new("Hash"),
vec![SmolStr::new("std"), SmolStr::new("hash"), SmolStr::new("Hash")],
),
(
SmolStr::new("Hasher"),
vec![SmolStr::new("std"), SmolStr::new("hash"), SmolStr::new("Hasher")],
),
(
SmolStr::new("Iterator"),
vec![SmolStr::new("std"), SmolStr::new("iter"), SmolStr::new("Iterator")],
),
];
ImportResolver { dummy_names }
}
// Returns a map of importable items filtered by name.
// The map associates item name with its full path.
// todo: should return Resolutions
pub(crate) fn all_names(
&self,
_db: &impl HirDatabase,
name: &Name,
) -> FxHashMap<SmolStr, Vec<SmolStr>> {
let name = name.to_smolstr();
if name.len() > 1 {
self.dummy_names
.iter()
.filter(|(n, _)| n.as_str().contains(name.as_str()))
.cloned()
.collect()
} else {
FxHashMap::default()
}
}
}