aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-01-09 15:09:49 +0000
committerAleksey Kladov <[email protected]>2019-01-09 16:40:11 +0000
commitddf2a8a948ed91bda14fef398c850c71c403ab59 (patch)
tree4b219aac4b876d5526b295beab1d7e0ee6272adc /crates
parentc2b8aa1ce5e5398d981387079e86ff67a5b7e8c0 (diff)
add completion detail
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_ide_api/src/completion/completion_item.rs12
-rw-r--r--crates/ra_lsp_server/src/conv.rs1
2 files changed, 13 insertions, 0 deletions
diff --git a/crates/ra_ide_api/src/completion/completion_item.rs b/crates/ra_ide_api/src/completion/completion_item.rs
index a25b87bee..d707a84ef 100644
--- a/crates/ra_ide_api/src/completion/completion_item.rs
+++ b/crates/ra_ide_api/src/completion/completion_item.rs
@@ -11,6 +11,7 @@ pub struct CompletionItem {
11 /// completion. 11 /// completion.
12 completion_kind: CompletionKind, 12 completion_kind: CompletionKind,
13 label: String, 13 label: String,
14 detail: Option<String>,
14 lookup: Option<String>, 15 lookup: Option<String>,
15 snippet: Option<String>, 16 snippet: Option<String>,
16 kind: Option<CompletionItemKind>, 17 kind: Option<CompletionItemKind>,
@@ -51,6 +52,7 @@ impl CompletionItem {
51 Builder { 52 Builder {
52 completion_kind, 53 completion_kind,
53 label, 54 label,
55 detail: None,
54 lookup: None, 56 lookup: None,
55 snippet: None, 57 snippet: None,
56 kind: None, 58 kind: None,
@@ -60,6 +62,10 @@ impl CompletionItem {
60 pub fn label(&self) -> &str { 62 pub fn label(&self) -> &str {
61 &self.label 63 &self.label
62 } 64 }
65 /// Short one-line additional information, like a type
66 pub fn detail(&self) -> Option<&str> {
67 self.detail.as_ref().map(|it| it.as_str())
68 }
63 /// What string is used for filtering. 69 /// What string is used for filtering.
64 pub fn lookup(&self) -> &str { 70 pub fn lookup(&self) -> &str {
65 self.lookup 71 self.lookup
@@ -87,6 +93,7 @@ impl CompletionItem {
87pub(crate) struct Builder { 93pub(crate) struct Builder {
88 completion_kind: CompletionKind, 94 completion_kind: CompletionKind,
89 label: String, 95 label: String,
96 detail: Option<String>,
90 lookup: Option<String>, 97 lookup: Option<String>,
91 snippet: Option<String>, 98 snippet: Option<String>,
92 kind: Option<CompletionItemKind>, 99 kind: Option<CompletionItemKind>,
@@ -100,6 +107,7 @@ impl Builder {
100 pub(crate) fn build(self) -> CompletionItem { 107 pub(crate) fn build(self) -> CompletionItem {
101 CompletionItem { 108 CompletionItem {
102 label: self.label, 109 label: self.label,
110 detail: self.detail,
103 lookup: self.lookup, 111 lookup: self.lookup,
104 snippet: self.snippet, 112 snippet: self.snippet,
105 kind: self.kind, 113 kind: self.kind,
@@ -118,6 +126,10 @@ impl Builder {
118 self.kind = Some(kind); 126 self.kind = Some(kind);
119 self 127 self
120 } 128 }
129 pub(crate) fn detail(mut self, detail: impl Into<String>) -> Builder {
130 self.detail = Some(detail.into());
131 self
132 }
121 pub(super) fn from_resolution( 133 pub(super) fn from_resolution(
122 mut self, 134 mut self,
123 ctx: &CompletionContext, 135 ctx: &CompletionContext,
diff --git a/crates/ra_lsp_server/src/conv.rs b/crates/ra_lsp_server/src/conv.rs
index 5c8b3c194..35c679a4a 100644
--- a/crates/ra_lsp_server/src/conv.rs
+++ b/crates/ra_lsp_server/src/conv.rs
@@ -75,6 +75,7 @@ impl Conv for CompletionItem {
75 fn conv(self) -> <Self as Conv>::Output { 75 fn conv(self) -> <Self as Conv>::Output {
76 let mut res = ::languageserver_types::CompletionItem { 76 let mut res = ::languageserver_types::CompletionItem {
77 label: self.label().to_string(), 77 label: self.label().to_string(),
78 detail: self.detail().map(|it| it.to_string()),
78 filter_text: Some(self.lookup().to_string()), 79 filter_text: Some(self.lookup().to_string()),
79 kind: self.kind().map(|it| it.conv()), 80 kind: self.kind().map(|it| it.conv()),
80 ..Default::default() 81 ..Default::default()