diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-07-16 21:18:28 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-07-16 21:18:28 +0100 |
commit | 81c82733899691fec7ed046525a5c583d3c7d5be (patch) | |
tree | 74f7814de8380f97c645afbfe3dad7d924785fcb /crates/ra_ide/src/display.rs | |
parent | 4759a39f06be1ec1469101a8aac39039b8743806 (diff) | |
parent | 3823c2dc1995ec261e36435662b8802c714e23d4 (diff) |
Merge #5415
5415: Remove FunctionSignature r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_ide/src/display.rs')
-rw-r--r-- | crates/ra_ide/src/display.rs | 62 |
1 files changed, 40 insertions, 22 deletions
diff --git a/crates/ra_ide/src/display.rs b/crates/ra_ide/src/display.rs index 1ec946369..6d4151dd8 100644 --- a/crates/ra_ide/src/display.rs +++ b/crates/ra_ide/src/display.rs | |||
@@ -1,7 +1,6 @@ | |||
1 | //! This module contains utilities for turning SyntaxNodes and HIR types | 1 | //! This module contains utilities for turning SyntaxNodes and HIR types |
2 | //! into types that may be used to render in a UI. | 2 | //! into types that may be used to render in a UI. |
3 | 3 | ||
4 | pub(crate) mod function_signature; | ||
5 | mod navigation_target; | 4 | mod navigation_target; |
6 | mod short_label; | 5 | mod short_label; |
7 | 6 | ||
@@ -10,13 +9,49 @@ use ra_syntax::{ | |||
10 | SyntaxKind::{ATTR, COMMENT}, | 9 | SyntaxKind::{ATTR, COMMENT}, |
11 | }; | 10 | }; |
12 | 11 | ||
13 | pub(crate) use navigation_target::{ToNav, TryToNav}; | 12 | use ast::VisibilityOwner; |
14 | pub(crate) use short_label::ShortLabel; | 13 | use stdx::format_to; |
15 | 14 | ||
16 | pub use navigation_target::NavigationTarget; | 15 | pub use navigation_target::NavigationTarget; |
16 | pub(crate) use navigation_target::{ToNav, TryToNav}; | ||
17 | pub(crate) use short_label::ShortLabel; | ||
17 | 18 | ||
18 | pub(crate) fn function_label(node: &ast::FnDef) -> String { | 19 | pub(crate) fn function_declaration(node: &ast::FnDef) -> String { |
19 | function_signature::FunctionSignature::from(node).to_string() | 20 | let mut buf = String::new(); |
21 | if let Some(vis) = node.visibility() { | ||
22 | format_to!(buf, "{} ", vis); | ||
23 | } | ||
24 | if node.async_token().is_some() { | ||
25 | format_to!(buf, "async "); | ||
26 | } | ||
27 | if node.const_token().is_some() { | ||
28 | format_to!(buf, "const "); | ||
29 | } | ||
30 | if node.unsafe_token().is_some() { | ||
31 | format_to!(buf, "unsafe "); | ||
32 | } | ||
33 | if let Some(abi) = node.abi() { | ||
34 | // Keyword `extern` is included in the string. | ||
35 | format_to!(buf, "{} ", abi); | ||
36 | } | ||
37 | if let Some(name) = node.name() { | ||
38 | format_to!(buf, "fn {}", name) | ||
39 | } | ||
40 | if let Some(type_params) = node.type_param_list() { | ||
41 | format_to!(buf, "{}", type_params); | ||
42 | } | ||
43 | if let Some(param_list) = node.param_list() { | ||
44 | format_to!(buf, "{}", param_list); | ||
45 | } | ||
46 | if let Some(ret_type) = node.ret_type() { | ||
47 | if ret_type.type_ref().is_some() { | ||
48 | format_to!(buf, " {}", ret_type); | ||
49 | } | ||
50 | } | ||
51 | if let Some(where_clause) = node.where_clause() { | ||
52 | format_to!(buf, "\n{}", where_clause); | ||
53 | } | ||
54 | buf | ||
20 | } | 55 | } |
21 | 56 | ||
22 | pub(crate) fn const_label(node: &ast::ConstDef) -> String { | 57 | pub(crate) fn const_label(node: &ast::ConstDef) -> String { |
@@ -41,23 +76,6 @@ pub(crate) fn type_label(node: &ast::TypeAliasDef) -> String { | |||
41 | label.trim().to_owned() | 76 | label.trim().to_owned() |
42 | } | 77 | } |
43 | 78 | ||
44 | pub(crate) fn generic_parameters<N: TypeParamsOwner>(node: &N) -> Vec<String> { | ||
45 | let mut res = vec![]; | ||
46 | if let Some(type_params) = node.type_param_list() { | ||
47 | res.extend(type_params.lifetime_params().map(|p| p.syntax().text().to_string())); | ||
48 | res.extend(type_params.type_params().map(|p| p.syntax().text().to_string())); | ||
49 | } | ||
50 | res | ||
51 | } | ||
52 | |||
53 | pub(crate) fn where_predicates<N: TypeParamsOwner>(node: &N) -> Vec<String> { | ||
54 | let mut res = vec![]; | ||
55 | if let Some(clause) = node.where_clause() { | ||
56 | res.extend(clause.predicates().map(|p| p.syntax().text().to_string())); | ||
57 | } | ||
58 | res | ||
59 | } | ||
60 | |||
61 | pub(crate) fn macro_label(node: &ast::MacroCall) -> String { | 79 | pub(crate) fn macro_label(node: &ast::MacroCall) -> String { |
62 | let name = node.name().map(|name| name.syntax().text().to_string()).unwrap_or_default(); | 80 | let name = node.name().map(|name| name.syntax().text().to_string()).unwrap_or_default(); |
63 | let vis = if node.has_atom_attr("macro_export") { "#[macro_export]\n" } else { "" }; | 81 | let vis = if node.has_atom_attr("macro_export") { "#[macro_export]\n" } else { "" }; |