aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_ide_api/src/completion/completion_item.rs16
-rw-r--r--crates/ra_lsp_server/src/conv.rs12
2 files changed, 26 insertions, 2 deletions
diff --git a/crates/ra_ide_api/src/completion/completion_item.rs b/crates/ra_ide_api/src/completion/completion_item.rs
index c892ad846..672c7ed0e 100644
--- a/crates/ra_ide_api/src/completion/completion_item.rs
+++ b/crates/ra_ide_api/src/completion/completion_item.rs
@@ -15,6 +15,7 @@ pub struct CompletionItem {
15 label: String, 15 label: String,
16 kind: Option<CompletionItemKind>, 16 kind: Option<CompletionItemKind>,
17 detail: Option<String>, 17 detail: Option<String>,
18 documentation: Option<String>,
18 lookup: Option<String>, 19 lookup: Option<String>,
19 insert_text: Option<String>, 20 insert_text: Option<String>,
20 insert_text_format: InsertTextFormat, 21 insert_text_format: InsertTextFormat,
@@ -77,6 +78,7 @@ impl CompletionItem {
77 insert_text: None, 78 insert_text: None,
78 insert_text_format: InsertTextFormat::PlainText, 79 insert_text_format: InsertTextFormat::PlainText,
79 detail: None, 80 detail: None,
81 documentation: None,
80 lookup: None, 82 lookup: None,
81 kind: None, 83 kind: None,
82 text_edit: None, 84 text_edit: None,
@@ -90,6 +92,10 @@ impl CompletionItem {
90 pub fn detail(&self) -> Option<&str> { 92 pub fn detail(&self) -> Option<&str> {
91 self.detail.as_ref().map(|it| it.as_str()) 93 self.detail.as_ref().map(|it| it.as_str())
92 } 94 }
95 /// A doc-comment
96 pub fn documentation(&self) -> Option<&str> {
97 self.documentation.as_ref().map(|it| it.as_str())
98 }
93 /// What string is used for filtering. 99 /// What string is used for filtering.
94 pub fn lookup(&self) -> &str { 100 pub fn lookup(&self) -> &str {
95 self.lookup 101 self.lookup
@@ -127,6 +133,7 @@ pub(crate) struct Builder {
127 insert_text: Option<String>, 133 insert_text: Option<String>,
128 insert_text_format: InsertTextFormat, 134 insert_text_format: InsertTextFormat,
129 detail: Option<String>, 135 detail: Option<String>,
136 documentation: Option<String>,
130 lookup: Option<String>, 137 lookup: Option<String>,
131 kind: Option<CompletionItemKind>, 138 kind: Option<CompletionItemKind>,
132 text_edit: Option<TextEdit>, 139 text_edit: Option<TextEdit>,
@@ -142,6 +149,7 @@ impl Builder {
142 source_range: self.source_range, 149 source_range: self.source_range,
143 label: self.label, 150 label: self.label,
144 detail: self.detail, 151 detail: self.detail,
152 documentation: self.documentation,
145 insert_text_format: self.insert_text_format, 153 insert_text_format: self.insert_text_format,
146 lookup: self.lookup, 154 lookup: self.lookup,
147 kind: self.kind, 155 kind: self.kind,
@@ -184,6 +192,14 @@ impl Builder {
184 self.detail = detail.map(Into::into); 192 self.detail = detail.map(Into::into);
185 self 193 self
186 } 194 }
195 #[allow(unused)]
196 pub(crate) fn documentation(self, docs: impl Into<String>) -> Builder {
197 self.set_documentation(Some(docs))
198 }
199 pub(crate) fn set_documentation(mut self, docs: Option<impl Into<String>>) -> Builder {
200 self.documentation = docs.map(Into::into);
201 self
202 }
187 pub(super) fn from_resolution( 203 pub(super) fn from_resolution(
188 mut self, 204 mut self,
189 ctx: &CompletionContext, 205 ctx: &CompletionContext,
diff --git a/crates/ra_lsp_server/src/conv.rs b/crates/ra_lsp_server/src/conv.rs
index 23b226fac..6818acaf6 100644
--- a/crates/ra_lsp_server/src/conv.rs
+++ b/crates/ra_lsp_server/src/conv.rs
@@ -1,6 +1,6 @@
1use lsp_types::{ 1use lsp_types::{
2 self, CreateFile, DocumentChangeOperation, DocumentChanges, Location, LocationLink, 2 self, CreateFile, Documentation, DocumentChangeOperation, DocumentChanges, Location, LocationLink,
3 Position, Range, RenameFile, ResourceOp, SymbolKind, TextDocumentEdit, TextDocumentIdentifier, 3 MarkupContent, MarkupKind, Position, Range, RenameFile, ResourceOp, SymbolKind, TextDocumentEdit, TextDocumentIdentifier,
4 TextDocumentItem, TextDocumentPositionParams, Url, VersionedTextDocumentIdentifier, 4 TextDocumentItem, TextDocumentPositionParams, Url, VersionedTextDocumentIdentifier,
5 WorkspaceEdit, 5 WorkspaceEdit,
6}; 6};
@@ -87,6 +87,13 @@ impl ConvWith for CompletionItem {
87 None 87 None
88 }; 88 };
89 89
90 let documentation = self.documentation().map(|value| {
91 Documentation::MarkupContent(MarkupContent {
92 kind: MarkupKind::Markdown,
93 value: value.to_string(),
94 })
95 });
96
90 let mut res = lsp_types::CompletionItem { 97 let mut res = lsp_types::CompletionItem {
91 label: self.label().to_string(), 98 label: self.label().to_string(),
92 detail: self.detail().map(|it| it.to_string()), 99 detail: self.detail().map(|it| it.to_string()),
@@ -94,6 +101,7 @@ impl ConvWith for CompletionItem {
94 kind: self.kind().map(|it| it.conv()), 101 kind: self.kind().map(|it| it.conv()),
95 text_edit: Some(text_edit), 102 text_edit: Some(text_edit),
96 additional_text_edits, 103 additional_text_edits,
104 documentation: documentation,
97 ..Default::default() 105 ..Default::default()
98 }; 106 };
99 res.insert_text_format = Some(match self.insert_text_format() { 107 res.insert_text_format = Some(match self.insert_text_format() {