diff options
author | Jeremy Kolb <[email protected]> | 2019-01-30 02:39:09 +0000 |
---|---|---|
committer | Jeremy Kolb <[email protected]> | 2019-01-30 02:39:09 +0000 |
commit | b88ba007cc2631799c2334753a7de807c548685e (patch) | |
tree | 0cbc02b9f764fdd8ff26e22135af281d3cbbd57f /crates/ra_ide_api/src/completion | |
parent | 48d2acb297459fb06cbb49bdce2eccb4c2591714 (diff) |
Pass Documentation up to LSP and add "rust" to our codeblocks there
Diffstat (limited to 'crates/ra_ide_api/src/completion')
-rw-r--r-- | crates/ra_ide_api/src/completion/completion_item.rs | 35 |
1 files changed, 10 insertions, 25 deletions
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 @@ | |||
1 | use hir::{Docs, Documentation}; | 1 | use hir::{Docs, Documentation}; |
2 | use ra_syntax::{ | 2 | use ra_syntax::TextRange; |
3 | ast::{self, AstNode}, | ||
4 | TextRange, | ||
5 | }; | ||
6 | use ra_text_edit::TextEdit; | 3 | use ra_text_edit::TextEdit; |
7 | use test_utils::tested_by; | 4 | use test_utils::tested_by; |
8 | 5 | ||
9 | use crate::completion::completion_context::CompletionContext; | 6 | use crate::completion::{ |
7 | completion_context::CompletionContext, | ||
8 | function_label, | ||
9 | }; | ||
10 | 10 | ||
11 | /// `CompletionItem` describes a single completion variant in the editor pop-up. | 11 | /// `CompletionItem` describes a single completion variant in the editor pop-up. |
12 | /// It is basically a POD with various properties. To construct a | 12 | /// It is basically a POD with various properties. To construct a |
@@ -97,8 +97,8 @@ impl CompletionItem { | |||
97 | self.detail.as_ref().map(|it| it.as_str()) | 97 | self.detail.as_ref().map(|it| it.as_str()) |
98 | } | 98 | } |
99 | /// A doc-comment | 99 | /// A doc-comment |
100 | pub fn documentation(&self) -> Option<&str> { | 100 | pub fn documentation(&self) -> Option<Documentation> { |
101 | self.documentation.as_ref().map(|it| it.contents()) | 101 | self.documentation.clone() |
102 | } | 102 | } |
103 | /// What string is used for filtering. | 103 | /// What string is used for filtering. |
104 | pub fn lookup(&self) -> &str { | 104 | pub fn lookup(&self) -> &str { |
@@ -252,7 +252,7 @@ impl Builder { | |||
252 | self.documentation = Some(docs); | 252 | self.documentation = Some(docs); |
253 | } | 253 | } |
254 | 254 | ||
255 | if let Some(label) = function_label(ctx, function) { | 255 | if let Some(label) = function_item_label(ctx, function) { |
256 | self.detail = Some(label); | 256 | self.detail = Some(label); |
257 | } | 257 | } |
258 | 258 | ||
@@ -292,24 +292,9 @@ impl Into<Vec<CompletionItem>> for Completions { | |||
292 | } | 292 | } |
293 | } | 293 | } |
294 | 294 | ||
295 | fn function_label(ctx: &CompletionContext, function: hir::Function) -> Option<String> { | 295 | fn function_item_label(ctx: &CompletionContext, function: hir::Function) -> Option<String> { |
296 | let node = function.source(ctx.db).1; | 296 | let node = function.source(ctx.db).1; |
297 | 297 | function_label(&node) | |
298 | let label: String = if let Some(body) = node.body() { | ||
299 | let body_range = body.syntax().range(); | ||
300 | let label: String = node | ||
301 | .syntax() | ||
302 | .children() | ||
303 | .filter(|child| !child.range().is_subrange(&body_range)) // Filter out body | ||
304 | .filter(|child| ast::Comment::cast(child).is_none()) // Filter out comments | ||
305 | .map(|node| node.text().to_string()) | ||
306 | .collect(); | ||
307 | label | ||
308 | } else { | ||
309 | node.syntax().text().to_string() | ||
310 | }; | ||
311 | |||
312 | Some(label.trim().to_owned()) | ||
313 | } | 298 | } |
314 | 299 | ||
315 | #[cfg(test)] | 300 | #[cfg(test)] |