From b88ba007cc2631799c2334753a7de807c548685e Mon Sep 17 00:00:00 2001 From: Jeremy Kolb Date: Tue, 29 Jan 2019 21:39:09 -0500 Subject: Pass Documentation up to LSP and add "rust" to our codeblocks there --- .../ra_ide_api/src/completion/completion_item.rs | 35 +++++++--------------- 1 file changed, 10 insertions(+), 25 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 49bd636a5..d3bc14894 100644 --- a/crates/ra_ide_api/src/completion/completion_item.rs +++ b/crates/ra_ide_api/src/completion/completion_item.rs @@ -1,12 +1,12 @@ use hir::{Docs, Documentation}; -use ra_syntax::{ - ast::{self, AstNode}, - TextRange, -}; +use ra_syntax::TextRange; use ra_text_edit::TextEdit; use test_utils::tested_by; -use crate::completion::completion_context::CompletionContext; +use crate::completion::{ + completion_context::CompletionContext, + function_label, +}; /// `CompletionItem` describes a single completion variant in the editor pop-up. /// It is basically a POD with various properties. To construct a @@ -97,8 +97,8 @@ impl CompletionItem { 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.contents()) + pub fn documentation(&self) -> Option { + self.documentation.clone() } /// What string is used for filtering. pub fn lookup(&self) -> &str { @@ -252,7 +252,7 @@ impl Builder { self.documentation = Some(docs); } - if let Some(label) = function_label(ctx, function) { + if let Some(label) = function_item_label(ctx, function) { self.detail = Some(label); } @@ -292,24 +292,9 @@ impl Into> for Completions { } } -fn function_label(ctx: &CompletionContext, function: hir::Function) -> Option { +fn function_item_label(ctx: &CompletionContext, function: hir::Function) -> Option { let node = function.source(ctx.db).1; - - let label: String = if let Some(body) = node.body() { - let body_range = body.syntax().range(); - let label: String = node - .syntax() - .children() - .filter(|child| !child.range().is_subrange(&body_range)) // Filter out body - .filter(|child| ast::Comment::cast(child).is_none()) // Filter out comments - .map(|node| node.text().to_string()) - .collect(); - label - } else { - node.syntax().text().to_string() - }; - - Some(label.trim().to_owned()) + function_label(&node) } #[cfg(test)] -- cgit v1.2.3