diff options
Diffstat (limited to 'crates/ra_ide_api/src/completion.rs')
-rw-r--r-- | crates/ra_ide_api/src/completion.rs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/crates/ra_ide_api/src/completion.rs b/crates/ra_ide_api/src/completion.rs index b1867de42..722d94f3a 100644 --- a/crates/ra_ide_api/src/completion.rs +++ b/crates/ra_ide_api/src/completion.rs | |||
@@ -10,6 +10,7 @@ mod complete_scope; | |||
10 | mod complete_postfix; | 10 | mod complete_postfix; |
11 | 11 | ||
12 | use ra_db::SourceDatabase; | 12 | use ra_db::SourceDatabase; |
13 | use ra_syntax::ast::{self, AstNode}; | ||
13 | 14 | ||
14 | use crate::{ | 15 | use crate::{ |
15 | db, | 16 | db, |
@@ -61,3 +62,21 @@ pub(crate) fn completions(db: &db::RootDatabase, position: FilePosition) -> Opti | |||
61 | complete_postfix::complete_postfix(&mut acc, &ctx); | 62 | complete_postfix::complete_postfix(&mut acc, &ctx); |
62 | Some(acc) | 63 | Some(acc) |
63 | } | 64 | } |
65 | |||
66 | pub fn function_label(node: &ast::FnDef) -> Option<String> { | ||
67 | let label: String = if let Some(body) = node.body() { | ||
68 | let body_range = body.syntax().range(); | ||
69 | let label: String = node | ||
70 | .syntax() | ||
71 | .children() | ||
72 | .filter(|child| !child.range().is_subrange(&body_range)) // Filter out body | ||
73 | .filter(|child| ast::Comment::cast(child).is_none()) // Filter out comments | ||
74 | .map(|node| node.text().to_string()) | ||
75 | .collect(); | ||
76 | label | ||
77 | } else { | ||
78 | node.syntax().text().to_string() | ||
79 | }; | ||
80 | |||
81 | Some(label.trim().to_owned()) | ||
82 | } | ||