mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 22:01:37 +00:00
Do name resolution by namespace (types/values)
This commit is contained in:
parent
b5b68f2094
commit
4ff1618520
10 changed files with 212 additions and 84 deletions
|
@ -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(()),
|
||||
};
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue