add completion detail

This commit is contained in:
Aleksey Kladov
2019-01-09 18:09:49 +03:00
parent c2b8aa1ce5
commit ddf2a8a948
2 changed files with 13 additions and 0 deletions
@@ -11,6 +11,7 @@ pub struct CompletionItem {
/// completion.
completion_kind: CompletionKind,
label: String,
detail: Option<String>,
lookup: Option<String>,
snippet: Option<String>,
kind: Option<CompletionItemKind>,
@@ -51,6 +52,7 @@ pub(crate) fn new(completion_kind: CompletionKind, label: impl Into<String>) ->
Builder {
completion_kind,
label,
detail: None,
lookup: None,
snippet: None,
kind: None,
@@ -60,6 +62,10 @@ pub(crate) fn new(completion_kind: CompletionKind, label: impl Into<String>) ->
pub fn label(&self) -> &str {
&self.label
}
/// Short one-line additional information, like a type
pub fn detail(&self) -> Option<&str> {
self.detail.as_ref().map(|it| it.as_str())
}
/// What string is used for filtering.
pub fn lookup(&self) -> &str {
self.lookup
@@ -87,6 +93,7 @@ pub fn kind(&self) -> Option<CompletionItemKind> {
pub(crate) struct Builder {
completion_kind: CompletionKind,
label: String,
detail: Option<String>,
lookup: Option<String>,
snippet: Option<String>,
kind: Option<CompletionItemKind>,
@@ -100,6 +107,7 @@ pub(crate) fn add_to(self, acc: &mut Completions) {
pub(crate) fn build(self) -> CompletionItem {
CompletionItem {
label: self.label,
detail: self.detail,
lookup: self.lookup,
snippet: self.snippet,
kind: self.kind,
@@ -118,6 +126,10 @@ pub(crate) fn kind(mut self, kind: CompletionItemKind) -> Builder {
self.kind = Some(kind);
self
}
pub(crate) fn detail(mut self, detail: impl Into<String>) -> Builder {
self.detail = Some(detail.into());
self
}
pub(super) fn from_resolution(
mut self,
ctx: &CompletionContext,
+1
View File
@@ -75,6 +75,7 @@ impl Conv for CompletionItem {
fn conv(self) -> <Self as Conv>::Output {
let mut res = ::languageserver_types::CompletionItem {
label: self.label().to_string(),
detail: self.detail().map(|it| it.to_string()),
filter_text: Some(self.lookup().to_string()),
kind: self.kind().map(|it| it.conv()),
..Default::default()