aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src/completion
diff options
context:
space:
mode:
authorJeremy A. Kolb <[email protected]>2019-01-22 23:20:40 +0000
committerJeremy A. Kolb <[email protected]>2019-01-22 23:20:40 +0000
commita3472f8fe16a359f9ea7a12e7b4920894921421e (patch)
tree6365cecd3c8e59246f22f7a10b86d96ae4462d8f /crates/ra_ide_api/src/completion
parent070a9802246123c79709271c9ba6fddd6f888813 (diff)
Move label from hir to ide_api
Diffstat (limited to 'crates/ra_ide_api/src/completion')
-rw-r--r--crates/ra_ide_api/src/completion/completion_item.rs27
1 files changed, 25 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 b720a1382..680fd8d1b 100644
--- a/crates/ra_ide_api/src/completion/completion_item.rs
+++ b/crates/ra_ide_api/src/completion/completion_item.rs
@@ -1,7 +1,10 @@
1use hir::PerNs; 1use hir::PerNs;
2 2
3use crate::completion::completion_context::CompletionContext; 3use crate::completion::completion_context::CompletionContext;
4use ra_syntax::TextRange; 4use ra_syntax::{
5 ast::{self, AstNode},
6 TextRange
7};
5use ra_text_edit::TextEdit; 8use ra_text_edit::TextEdit;
6 9
7/// `CompletionItem` describes a single completion variant in the editor pop-up. 10/// `CompletionItem` describes a single completion variant in the editor pop-up.
@@ -263,7 +266,7 @@ impl Builder {
263 self.documentation = Some(docs); 266 self.documentation = Some(docs);
264 } 267 }
265 268
266 if let Some(label) = function.label(ctx.db) { 269 if let Some(label) = function_label(ctx, function) {
267 self.detail = Some(label); 270 self.detail = Some(label);
268 } 271 }
269 272
@@ -303,6 +306,26 @@ impl Into<Vec<CompletionItem>> for Completions {
303 } 306 }
304} 307}
305 308
309fn function_label(ctx: &CompletionContext, function: hir::Function) -> Option<String> {
310 let node = function.source(ctx.db).1;
311
312 let label: String = if let Some(body) = node.body() {
313 let body_range = body.syntax().range();
314 let label: String = node
315 .syntax()
316 .children()
317 .filter(|child| !child.range().is_subrange(&body_range)) // Filter out body
318 .filter(|child| ast::Comment::cast(child).is_none()) // Filter out comments
319 .map(|node| node.text().to_string())
320 .collect();
321 label
322 } else {
323 node.syntax().text().to_string()
324 };
325
326 Some(label.trim().to_owned())
327}
328
306#[cfg(test)] 329#[cfg(test)]
307pub(crate) fn check_completion(test_name: &str, code: &str, kind: CompletionKind) { 330pub(crate) fn check_completion(test_name: &str, code: &str, kind: CompletionKind) {
308 use crate::mock_analysis::{single_file_with_position, analysis_and_position}; 331 use crate::mock_analysis::{single_file_with_position, analysis_and_position};