make compleion item details private

This commit is contained in:
Aleksey Kladov 2018-12-21 15:19:46 +03:00
parent b5c5995bf1
commit 4092b8d0b5
5 changed files with 65 additions and 36 deletions

View file

@ -1,11 +1,13 @@
#[derive(Debug)]
pub struct CompletionItem {
/// What user sees in pop-up in the UI.
pub label: String,
/// What string is used for filtering, defaults to label.
pub lookup: Option<String>,
/// What is inserted, defaults to label.
pub snippet: Option<String>,
label: String,
lookup: Option<String>,
snippet: Option<String>,
}
pub enum InsertText {
PlainText { text: String },
Snippet { text: String },
}
impl CompletionItem {
@ -17,6 +19,26 @@ impl CompletionItem {
snippet: None,
}
}
/// What user sees in pop-up in the UI.
pub fn label(&self) -> &str {
&self.label
}
/// What string is used for filtering.
pub fn lookup(&self) -> &str {
self.lookup
.as_ref()
.map(|it| it.as_str())
.unwrap_or(self.label())
}
/// What is inserted.
pub fn insert_text(&self) -> InsertText {
match &self.snippet {
None => InsertText::PlainText {
text: self.label.clone(),
},
Some(it) => InsertText::Snippet { text: it.clone() },
}
}
}
#[must_use]

View file

@ -39,25 +39,19 @@ pub(super) fn completions(
}
let module_scope = module.scope(db)?;
acc.extend(
module_scope
.entries()
.filter(|(_name, res)| {
// Don't expose this item
match res.import {
None => true,
Some(import) => {
let range = import.range(db, module.source().file_id());
!range.is_subrange(&name_ref.syntax().range())
}
module_scope
.entries()
.filter(|(_name, res)| {
// Don't expose this item
match res.import {
None => true,
Some(import) => {
let range = import.range(db, module.source().file_id());
!range.is_subrange(&name_ref.syntax().range())
}
})
.map(|(name, _res)| CompletionItem {
label: name.to_string(),
lookup: None,
snippet: None,
}),
);
}
})
.for_each(|(name, _res)| CompletionItem::new(name.to_string()).add_to(acc));
}
NameRefKind::Path(path) => complete_path(acc, db, module, path)?,
NameRefKind::BareIdentInMod => {