aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src/completion.rs
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-04-09 18:55:44 +0100
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-04-09 18:55:44 +0100
commit2fc2d4373b2c4e96bebf320a84270eee3afe34aa (patch)
tree5bdb33ae377b4004f0b28ec5e2edff71b41e8c4e /crates/ra_ide_api/src/completion.rs
parent5f700179fc7ed16d2848a6dbc7cf23da3b8df6c7 (diff)
parent45a2b9252401cc580dfa2e0e761313cc8334d47c (diff)
Merge #1110
1110: Introduce display module and implement new FunctionSignature for CallInfo's r=matklad a=vipentti This introduces a new module `display` in `ra_ide_api` that contains UI-related things, in addition this refactors CallInfo's function signatures into a new `FunctionSignature` type, which implements `Display` and can be converted into `lsp_types::SignatureInformation` in the `conv` layer. Currently only `CallInfo` uses the `FunctionSignature` directly, but `function_label` now uses the same signature and returns it as a string, using the `Display` implementation. This also fixes #960 I think this similar structure could be applied to other UI-displayable items, so instead of the `ra_ide_api` returning `Strings` we could return some intermediate structures that can be converted into a UI-displayable `String` easily, but that could also provide some additional information. Co-authored-by: Ville Penttinen <[email protected]>
Diffstat (limited to 'crates/ra_ide_api/src/completion.rs')
-rw-r--r--crates/ra_ide_api/src/completion.rs41
1 files changed, 0 insertions, 41 deletions
diff --git a/crates/ra_ide_api/src/completion.rs b/crates/ra_ide_api/src/completion.rs
index a846a7a3c..deff59cd3 100644
--- a/crates/ra_ide_api/src/completion.rs
+++ b/crates/ra_ide_api/src/completion.rs
@@ -13,7 +13,6 @@ mod complete_scope;
13mod complete_postfix; 13mod complete_postfix;
14 14
15use ra_db::SourceDatabase; 15use ra_db::SourceDatabase;
16use ra_syntax::{ast::{self, AstNode}, SyntaxKind::{ATTR, COMMENT}};
17 16
18use crate::{ 17use crate::{
19 db, 18 db,
@@ -70,43 +69,3 @@ pub(crate) fn completions(db: &db::RootDatabase, position: FilePosition) -> Opti
70 complete_postfix::complete_postfix(&mut acc, &ctx); 69 complete_postfix::complete_postfix(&mut acc, &ctx);
71 Some(acc) 70 Some(acc)
72} 71}
73
74pub fn function_label(node: &ast::FnDef) -> Option<String> {
75 let label: String = if let Some(body) = node.body() {
76 let body_range = body.syntax().range();
77 let label: String = node
78 .syntax()
79 .children_with_tokens()
80 .filter(|child| !child.range().is_subrange(&body_range)) // Filter out body
81 .filter(|child| !(child.kind() == COMMENT || child.kind() == ATTR)) // Filter out comments and attrs
82 .map(|node| node.to_string())
83 .collect();
84 label
85 } else {
86 node.syntax().text().to_string()
87 };
88
89 Some(label.trim().to_owned())
90}
91
92pub fn const_label(node: &ast::ConstDef) -> String {
93 let label: String = node
94 .syntax()
95 .children_with_tokens()
96 .filter(|child| !(child.kind() == COMMENT || child.kind() == ATTR))
97 .map(|node| node.to_string())
98 .collect();
99
100 label.trim().to_owned()
101}
102
103pub fn type_label(node: &ast::TypeAliasDef) -> String {
104 let label: String = node
105 .syntax()
106 .children_with_tokens()
107 .filter(|child| !(child.kind() == COMMENT || child.kind() == ATTR))
108 .map(|node| node.to_string())
109 .collect();
110
111 label.trim().to_owned()
112}