From 5d110c0ee2ec50009eb7c552888a73ce8380d34a Mon Sep 17 00:00:00 2001 From: Jeremy Kolb Date: Mon, 21 Jan 2019 21:41:39 -0500 Subject: Teach CompletionItem about documentation --- crates/ra_ide_api/src/completion/completion_item.rs | 16 ++++++++++++++++ crates/ra_lsp_server/src/conv.rs | 12 ++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) (limited to 'crates') 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 { label: String, kind: Option, detail: Option, + documentation: Option, lookup: Option, insert_text: Option, insert_text_format: InsertTextFormat, @@ -77,6 +78,7 @@ impl CompletionItem { insert_text: None, insert_text_format: InsertTextFormat::PlainText, detail: None, + documentation: None, lookup: None, kind: None, text_edit: None, @@ -90,6 +92,10 @@ impl CompletionItem { pub fn detail(&self) -> Option<&str> { self.detail.as_ref().map(|it| it.as_str()) } + /// A doc-comment + pub fn documentation(&self) -> Option<&str> { + self.documentation.as_ref().map(|it| it.as_str()) + } /// What string is used for filtering. pub fn lookup(&self) -> &str { self.lookup @@ -127,6 +133,7 @@ pub(crate) struct Builder { insert_text: Option, insert_text_format: InsertTextFormat, detail: Option, + documentation: Option, lookup: Option, kind: Option, text_edit: Option, @@ -142,6 +149,7 @@ impl Builder { source_range: self.source_range, label: self.label, detail: self.detail, + documentation: self.documentation, insert_text_format: self.insert_text_format, lookup: self.lookup, kind: self.kind, @@ -184,6 +192,14 @@ impl Builder { self.detail = detail.map(Into::into); self } + #[allow(unused)] + pub(crate) fn documentation(self, docs: impl Into) -> Builder { + self.set_documentation(Some(docs)) + } + pub(crate) fn set_documentation(mut self, docs: Option>) -> Builder { + self.documentation = docs.map(Into::into); + self + } pub(super) fn from_resolution( mut self, 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 @@ use lsp_types::{ - self, CreateFile, DocumentChangeOperation, DocumentChanges, Location, LocationLink, - Position, Range, RenameFile, ResourceOp, SymbolKind, TextDocumentEdit, TextDocumentIdentifier, + self, CreateFile, Documentation, DocumentChangeOperation, DocumentChanges, Location, LocationLink, + MarkupContent, MarkupKind, Position, Range, RenameFile, ResourceOp, SymbolKind, TextDocumentEdit, TextDocumentIdentifier, TextDocumentItem, TextDocumentPositionParams, Url, VersionedTextDocumentIdentifier, WorkspaceEdit, }; @@ -87,6 +87,13 @@ impl ConvWith for CompletionItem { None }; + let documentation = self.documentation().map(|value| { + Documentation::MarkupContent(MarkupContent { + kind: MarkupKind::Markdown, + value: value.to_string(), + }) + }); + let mut res = lsp_types::CompletionItem { label: self.label().to_string(), detail: self.detail().map(|it| it.to_string()), @@ -94,6 +101,7 @@ impl ConvWith for CompletionItem { kind: self.kind().map(|it| it.conv()), text_edit: Some(text_edit), additional_text_edits, + documentation: documentation, ..Default::default() }; res.insert_text_format = Some(match self.insert_text_format() { -- cgit v1.2.3