Do name resolution by namespace (types/values)

This commit is contained in:
Florian Diebold 2018-12-24 20:32:39 +01:00
parent b5b68f2094
commit 4ff1618520
10 changed files with 212 additions and 84 deletions

View file

@ -8,7 +8,7 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) -> C
(Some(path), Some(module)) => (path.clone(), module),
_ => return Ok(()),
};
let def_id = match module.resolve_path(ctx.db, path)? {
let def_id = match module.resolve_path(ctx.db, path)?.take_types() {
Some(it) => it,
None => return Ok(()),
};

View file

@ -1,5 +1,7 @@
use crate::db;
use hir::PerNs;
/// `CompletionItem` describes a single completion variant in the editor pop-up.
/// It is basically a POD with various properties. To construct a
/// `CompletionItem`, use `new` method and the `Builder` struct.
@ -25,6 +27,8 @@ pub enum CompletionItemKind {
Keyword,
Module,
Function,
Struct,
Enum,
Binding,
}
@ -117,16 +121,27 @@ impl Builder {
db: &db::RootDatabase,
resolution: &hir::Resolution,
) -> Builder {
if let Some(def_id) = resolution.def_id {
if let Ok(def) = def_id.resolve(db) {
let kind = match def {
hir::Def::Module(..) => CompletionItemKind::Module,
hir::Def::Function(..) => CompletionItemKind::Function,
_ => return self,
};
self.kind = Some(kind);
}
}
let resolved = resolution.def_id.and_then(|d| d.resolve(db).ok());
let kind = match resolved {
PerNs {
types: Some(hir::Def::Module(..)),
..
} => CompletionItemKind::Module,
PerNs {
types: Some(hir::Def::Struct(..)),
..
} => CompletionItemKind::Struct,
PerNs {
types: Some(hir::Def::Enum(..)),
..
} => CompletionItemKind::Enum,
PerNs {
values: Some(hir::Def::Function(..)),
..
} => CompletionItemKind::Function,
_ => return self,
};
self.kind = Some(kind);
self
}
}

View file

@ -95,8 +95,8 @@ salsa::database_storage! {
fn submodules() for hir::db::SubmodulesQuery;
fn infer() for hir::db::InferQuery;
fn type_for_def() for hir::db::TypeForDefQuery;
fn struct_data() for db::StructDataQuery;
fn enum_data() for db::EnumDataQuery;
fn struct_data() for hir::db::StructDataQuery;
fn enum_data() for hir::db::EnumDataQuery;
}
}
}