diff options
author | Ville Penttinen <[email protected]> | 2019-04-08 09:44:23 +0100 |
---|---|---|
committer | Ville Penttinen <[email protected]> | 2019-04-09 12:45:05 +0100 |
commit | 946b5789d1ea6385a345fcb4aa0658392ec44a51 (patch) | |
tree | e5c517463b5c3b0e6727c5b0717e0f03ee452fe4 /crates | |
parent | dfaebd76aba1cfd7ac13b940d7847eb44b953cac (diff) |
Move completion label functions to display
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_ide_api/src/completion.rs | 28 | ||||
-rw-r--r-- | crates/ra_ide_api/src/completion/presentation.rs | 5 | ||||
-rw-r--r-- | crates/ra_ide_api/src/display.rs | 28 | ||||
-rw-r--r-- | crates/ra_ide_api/src/hover.rs | 2 |
4 files changed, 32 insertions, 31 deletions
diff --git a/crates/ra_ide_api/src/completion.rs b/crates/ra_ide_api/src/completion.rs index 71a35c689..deff59cd3 100644 --- a/crates/ra_ide_api/src/completion.rs +++ b/crates/ra_ide_api/src/completion.rs | |||
@@ -13,12 +13,10 @@ mod complete_scope; | |||
13 | mod complete_postfix; | 13 | mod complete_postfix; |
14 | 14 | ||
15 | use ra_db::SourceDatabase; | 15 | use ra_db::SourceDatabase; |
16 | use ra_syntax::{ast::{self, AstNode}, SyntaxKind::{ATTR, COMMENT}}; | ||
17 | 16 | ||
18 | use crate::{ | 17 | use crate::{ |
19 | db, | 18 | db, |
20 | FilePosition, | 19 | FilePosition, |
21 | FunctionSignature, | ||
22 | completion::{ | 20 | completion::{ |
23 | completion_item::{Completions, CompletionKind}, | 21 | completion_item::{Completions, CompletionKind}, |
24 | completion_context::CompletionContext, | 22 | completion_context::CompletionContext, |
@@ -71,29 +69,3 @@ pub(crate) fn completions(db: &db::RootDatabase, position: FilePosition) -> Opti | |||
71 | complete_postfix::complete_postfix(&mut acc, &ctx); | 69 | complete_postfix::complete_postfix(&mut acc, &ctx); |
72 | Some(acc) | 70 | Some(acc) |
73 | } | 71 | } |
74 | |||
75 | pub fn function_label(node: &ast::FnDef) -> Option<String> { | ||
76 | Some(FunctionSignature::from(node).to_string()) | ||
77 | } | ||
78 | |||
79 | pub fn const_label(node: &ast::ConstDef) -> String { | ||
80 | let label: String = node | ||
81 | .syntax() | ||
82 | .children_with_tokens() | ||
83 | .filter(|child| !(child.kind() == COMMENT || child.kind() == ATTR)) | ||
84 | .map(|node| node.to_string()) | ||
85 | .collect(); | ||
86 | |||
87 | label.trim().to_owned() | ||
88 | } | ||
89 | |||
90 | pub fn type_label(node: &ast::TypeAliasDef) -> String { | ||
91 | let label: String = node | ||
92 | .syntax() | ||
93 | .children_with_tokens() | ||
94 | .filter(|child| !(child.kind() == COMMENT || child.kind() == ATTR)) | ||
95 | .map(|node| node.to_string()) | ||
96 | .collect(); | ||
97 | |||
98 | label.trim().to_owned() | ||
99 | } | ||
diff --git a/crates/ra_ide_api/src/completion/presentation.rs b/crates/ra_ide_api/src/completion/presentation.rs index 28c8f83ab..9aa346688 100644 --- a/crates/ra_ide_api/src/completion/presentation.rs +++ b/crates/ra_ide_api/src/completion/presentation.rs | |||
@@ -6,6 +6,9 @@ use ra_syntax::ast::NameOwner; | |||
6 | 6 | ||
7 | use crate::completion::{ | 7 | use crate::completion::{ |
8 | Completions, CompletionKind, CompletionItemKind, CompletionContext, CompletionItem, | 8 | Completions, CompletionKind, CompletionItemKind, CompletionContext, CompletionItem, |
9 | }; | ||
10 | |||
11 | use crate::display::{ | ||
9 | function_label, const_label, type_label, | 12 | function_label, const_label, type_label, |
10 | }; | 13 | }; |
11 | 14 | ||
@@ -101,7 +104,7 @@ impl Completions { | |||
101 | CompletionItemKind::Function | 104 | CompletionItemKind::Function |
102 | }) | 105 | }) |
103 | .set_documentation(func.docs(ctx.db)) | 106 | .set_documentation(func.docs(ctx.db)) |
104 | .set_detail(detail); | 107 | .detail(detail); |
105 | // If not an import, add parenthesis automatically. | 108 | // If not an import, add parenthesis automatically. |
106 | if ctx.use_item_syntax.is_none() && !ctx.is_call { | 109 | if ctx.use_item_syntax.is_none() && !ctx.is_call { |
107 | tested_by!(inserts_parens_for_function_calls); | 110 | tested_by!(inserts_parens_for_function_calls); |
diff --git a/crates/ra_ide_api/src/display.rs b/crates/ra_ide_api/src/display.rs index c05d59689..efadb9b10 100644 --- a/crates/ra_ide_api/src/display.rs +++ b/crates/ra_ide_api/src/display.rs | |||
@@ -3,10 +3,36 @@ | |||
3 | use super::*; | 3 | use super::*; |
4 | use std::fmt::{self, Display}; | 4 | use std::fmt::{self, Display}; |
5 | use join_to_string::join; | 5 | use join_to_string::join; |
6 | use ra_syntax::ast::{self, AstNode, NameOwner, VisibilityOwner, TypeParamsOwner}; | 6 | use ra_syntax::{ast::{self, AstNode, NameOwner, VisibilityOwner, TypeParamsOwner}, SyntaxKind::{ATTR, COMMENT}}; |
7 | use std::convert::From; | 7 | use std::convert::From; |
8 | use hir::Docs; | 8 | use hir::Docs; |
9 | 9 | ||
10 | pub(crate) fn function_label(node: &ast::FnDef) -> String { | ||
11 | FunctionSignature::from(node).to_string() | ||
12 | } | ||
13 | |||
14 | pub(crate) fn const_label(node: &ast::ConstDef) -> String { | ||
15 | let label: String = node | ||
16 | .syntax() | ||
17 | .children_with_tokens() | ||
18 | .filter(|child| !(child.kind() == COMMENT || child.kind() == ATTR)) | ||
19 | .map(|node| node.to_string()) | ||
20 | .collect(); | ||
21 | |||
22 | label.trim().to_owned() | ||
23 | } | ||
24 | |||
25 | pub(crate) fn type_label(node: &ast::TypeAliasDef) -> String { | ||
26 | let label: String = node | ||
27 | .syntax() | ||
28 | .children_with_tokens() | ||
29 | .filter(|child| !(child.kind() == COMMENT || child.kind() == ATTR)) | ||
30 | .map(|node| node.to_string()) | ||
31 | .collect(); | ||
32 | |||
33 | label.trim().to_owned() | ||
34 | } | ||
35 | |||
10 | /// Contains information about a function signature | 36 | /// Contains information about a function signature |
11 | #[derive(Debug)] | 37 | #[derive(Debug)] |
12 | pub struct FunctionSignature { | 38 | pub struct FunctionSignature { |
diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs index bfa7cd67a..7d2c57f82 100644 --- a/crates/ra_ide_api/src/hover.rs +++ b/crates/ra_ide_api/src/hover.rs | |||
@@ -235,7 +235,7 @@ impl NavigationTarget { | |||
235 | } | 235 | } |
236 | 236 | ||
237 | visitor() | 237 | visitor() |
238 | .visit(crate::completion::function_label) | 238 | .visit(|node: &ast::FnDef| Some(crate::display::function_label(node))) |
239 | .visit(|node: &ast::StructDef| visit_node(node, "struct ")) | 239 | .visit(|node: &ast::StructDef| visit_node(node, "struct ")) |
240 | .visit(|node: &ast::EnumDef| visit_node(node, "enum ")) | 240 | .visit(|node: &ast::EnumDef| visit_node(node, "enum ")) |
241 | .visit(|node: &ast::TraitDef| visit_node(node, "trait ")) | 241 | .visit(|node: &ast::TraitDef| visit_node(node, "trait ")) |