moar icons

This commit is contained in:
Aleksey Kladov 2018-12-22 02:20:14 +03:00
parent 238b52358d
commit 97cb463c9b
7 changed files with 34 additions and 7 deletions

View file

@ -17,8 +17,10 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) -> C
_ => return Ok(()), _ => return Ok(()),
}; };
let module_scope = target_module.scope(ctx.db)?; let module_scope = target_module.scope(ctx.db)?;
module_scope.entries().for_each(|(name, _res)| { module_scope.entries().for_each(|(name, res)| {
CompletionItem::new(CompletionKind::Reference, name.to_string()).add_to(acc) CompletionItem::new(CompletionKind::Reference, name.to_string())
.from_resolution(ctx.db, res)
.add_to(acc)
}); });
Ok(()) Ok(())
} }

View file

@ -29,8 +29,10 @@ pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) ->
} }
} }
}) })
.for_each(|(name, _res)| { .for_each(|(name, res)| {
CompletionItem::new(CompletionKind::Reference, name.to_string()).add_to(acc) CompletionItem::new(CompletionKind::Reference, name.to_string())
.from_resolution(ctx.db, res)
.add_to(acc)
}); });
} }

View file

@ -1,3 +1,5 @@
use crate::db;
/// `CompletionItem` describes a single completion variant in the editor pop-up. /// `CompletionItem` describes a single completion variant in the editor pop-up.
/// It is basically a POD with various properties. To construct a /// It is basically a POD with various properties. To construct a
/// `CompletionItem`, use `new` method and the `Builder` struct. /// `CompletionItem`, use `new` method and the `Builder` struct.
@ -21,6 +23,8 @@ pub enum InsertText {
pub enum CompletionItemKind { pub enum CompletionItemKind {
Snippet, Snippet,
Keyword, Keyword,
Module,
Function,
} }
#[derive(Debug, PartialEq, Eq)] #[derive(Debug, PartialEq, Eq)]
@ -107,6 +111,23 @@ impl Builder {
self.kind = Some(kind); self.kind = Some(kind);
self self
} }
pub(crate) fn from_resolution(
mut self,
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);
}
}
self
}
} }
impl Into<CompletionItem> for Builder { impl Into<CompletionItem> for Builder {

View file

@ -39,7 +39,7 @@ use crate::{
pub use self::{ pub use self::{
path::{Path, PathKind}, path::{Path, PathKind},
krate::Crate, krate::Crate,
module::{Module, ModuleId, Problem, nameres::ItemMap}, module::{Module, ModuleId, Problem, nameres::ItemMap, ModuleScope, Resolution},
function::{Function, FnScopes}, function::{Function, FnScopes},
}; };

View file

@ -16,7 +16,7 @@ use crate::{
arena::{Arena, Id}, arena::{Arena, Id},
}; };
pub use self::nameres::ModuleScope; pub use self::nameres::{ModuleScope, Resolution};
/// `Module` is API entry point to get all the information /// `Module` is API entry point to get all the information
/// about a particular module. /// about a particular module.

View file

@ -49,7 +49,7 @@ pub struct ModuleScope {
} }
impl ModuleScope { impl ModuleScope {
pub fn entries<'a>(&'a self) -> impl Iterator<Item = (&'a SmolStr, &Resolution)> + 'a { pub fn entries<'a>(&'a self) -> impl Iterator<Item = (&'a SmolStr, &'a Resolution)> + 'a {
self.items.iter() self.items.iter()
} }
pub fn get(&self, name: &SmolStr) -> Option<&Resolution> { pub fn get(&self, name: &SmolStr) -> Option<&Resolution> {

View file

@ -53,6 +53,8 @@ impl Conv for CompletionItemKind {
match self { match self {
CompletionItemKind::Keyword => Keyword, CompletionItemKind::Keyword => Keyword,
CompletionItemKind::Snippet => Snippet, CompletionItemKind::Snippet => Snippet,
CompletionItemKind::Module => Module,
CompletionItemKind::Function => Function,
} }
} }
} }