Return documentation with completion results

This commit is contained in:
Tad Hardesty 2019-07-14 20:18:33 -07:00
parent 1fb53dc003
commit a0cdb4fe44
2 changed files with 26 additions and 1 deletions

View file

@ -32,6 +32,15 @@ pub enum Define {
},
}
impl Define {
pub fn docs(&self) -> &DocCollection {
match self {
Define::Constant { docs, .. } => docs,
Define::Function { docs, .. } => docs,
}
}
}
impl fmt::Display for Define {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
let subst = match self {

View file

@ -29,11 +29,12 @@ pub fn item_var(ty: TypeRef, name: &str, var: &TypeVar) -> CompletionItem {
label: name.to_owned(),
kind: Some(CompletionItemKind::Field),
detail: Some(detail),
documentation: item_documentation(&var.value.docs),
.. Default::default()
}
}
pub fn item_proc(ty: TypeRef, name: &str, _proc: &TypeProc) -> CompletionItem {
pub fn item_proc(ty: TypeRef, name: &str, proc: &TypeProc) -> CompletionItem {
CompletionItem {
label: name.to_owned(),
kind: Some(if ty.is_root() {
@ -44,10 +45,22 @@ pub fn item_proc(ty: TypeRef, name: &str, _proc: &TypeProc) -> CompletionItem {
CompletionItemKind::Method
}),
detail: Some(ty.pretty_path().to_owned()),
documentation: item_documentation(&proc.main_value().docs),
..Default::default()
}
}
pub fn item_documentation(docs: &dm::docs::DocCollection) -> Option<Documentation> {
if docs.is_empty() {
return None;
}
Some(Documentation::MarkupContent(MarkupContent {
kind: MarkupKind::Markdown,
value: docs.text(),
}))
}
pub fn items_ty<'a>(
results: &mut Vec<CompletionItem>,
skip: &mut HashSet<(&str, &'a String)>,
@ -195,6 +208,7 @@ impl<'a, W: io::ResponseWrite> Engine<'a, W> {
results.push(CompletionItem {
label: child.name.to_owned(),
kind: Some(CompletionItemKind::Class),
documentation: item_documentation(&child.docs),
.. Default::default()
});
}
@ -282,6 +296,7 @@ impl<'a, W: io::ResponseWrite> Engine<'a, W> {
results.push(CompletionItem {
label: child.name.to_owned(),
kind: Some(CompletionItemKind::Class),
documentation: item_documentation(&child.docs),
.. Default::default()
});
}
@ -382,6 +397,7 @@ impl<'a, W: io::ResponseWrite> Engine<'a, W> {
label: name.to_owned(),
kind: Some(CompletionItemKind::Constant),
detail: Some(format!("{}", define)),
documentation: item_documentation(define.docs()),
.. Default::default()
});
}