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 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'crates/ra_ide_api/src/completion/completion_item.rs') 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, -- cgit v1.2.3 From b77d780f0e9e7902695b949a25588fcb66bb5982 Mon Sep 17 00:00:00 2001 From: Jeremy Kolb Date: Mon, 21 Jan 2019 21:42:37 -0500 Subject: Thread documentation through FnSignature and CompletionItem --- crates/ra_ide_api/src/completion/completion_item.rs | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'crates/ra_ide_api/src/completion/completion_item.rs') diff --git a/crates/ra_ide_api/src/completion/completion_item.rs b/crates/ra_ide_api/src/completion/completion_item.rs index 672c7ed0e..dfaadbb20 100644 --- a/crates/ra_ide_api/src/completion/completion_item.rs +++ b/crates/ra_ide_api/src/completion/completion_item.rs @@ -259,6 +259,11 @@ impl Builder { } self.insert_text_format = InsertTextFormat::Snippet; } + let sig = function.signature(ctx.db); + if !sig.documentation().is_empty() { + self.documentation = Some(sig.documentation().clone()); + } + self.kind = Some(CompletionItemKind::Function); self } -- cgit v1.2.3 From b5404514834a27c682dc22d86bc5585c0cae3076 Mon Sep 17 00:00:00 2001 From: Jeremy Kolb Date: Tue, 22 Jan 2019 08:55:05 -0500 Subject: Move docs to Function --- crates/ra_ide_api/src/completion/completion_item.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'crates/ra_ide_api/src/completion/completion_item.rs') diff --git a/crates/ra_ide_api/src/completion/completion_item.rs b/crates/ra_ide_api/src/completion/completion_item.rs index dfaadbb20..d70c36889 100644 --- a/crates/ra_ide_api/src/completion/completion_item.rs +++ b/crates/ra_ide_api/src/completion/completion_item.rs @@ -259,9 +259,8 @@ impl Builder { } self.insert_text_format = InsertTextFormat::Snippet; } - let sig = function.signature(ctx.db); - if !sig.documentation().is_empty() { - self.documentation = Some(sig.documentation().clone()); + if let Some(docs) = function.docs(ctx.db) { + self.documentation = Some(docs); } self.kind = Some(CompletionItemKind::Function); -- cgit v1.2.3