diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-10-18 11:41:46 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-10-18 11:41:46 +0100 |
commit | 886cfd68212bb0b4487d6a822476c350a6eb114f (patch) | |
tree | 5b144eabe1eaf62aa1ec5b804ee6fff00f5f84e9 /crates/ide/src/display.rs | |
parent | 2067a410f31810f6e1941a86cdea0247c3b7d6f4 (diff) | |
parent | 9e7c952bbddc2e6763c49f0511a295362e9893d6 (diff) |
Merge #6276
6276: Extract call_info and completion into separate crates r=matklad a=popzxc
As it was discussed in [zulip](https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/Completion.20refactoring), we need to move `completions` into a separate crate.
Unfortunately, the dependency on `call_info::ActiveParameter` doesn't look easy to get rid of, and it seems to be a topic for a separate PR, thus I also extracted `call_info` into a separate crate (on which both `ide` and `completion` crates depend).
Additionally, a few `FIXME`s in doc-comments were resolved in order to make `tidy` happy.
Co-authored-by: Igor Aleksanov <[email protected]>
Diffstat (limited to 'crates/ide/src/display.rs')
-rw-r--r-- | crates/ide/src/display.rs | 81 |
1 files changed, 1 insertions, 80 deletions
diff --git a/crates/ide/src/display.rs b/crates/ide/src/display.rs index 2484dbbf1..0650915c5 100644 --- a/crates/ide/src/display.rs +++ b/crates/ide/src/display.rs | |||
@@ -4,87 +4,8 @@ | |||
4 | mod navigation_target; | 4 | mod navigation_target; |
5 | mod short_label; | 5 | mod short_label; |
6 | 6 | ||
7 | use syntax::{ | ||
8 | ast::{self, AstNode, AttrsOwner, GenericParamsOwner, NameOwner}, | ||
9 | SyntaxKind::{ATTR, COMMENT}, | ||
10 | }; | ||
11 | |||
12 | use ast::VisibilityOwner; | ||
13 | use stdx::format_to; | ||
14 | |||
15 | pub use navigation_target::NavigationTarget; | 7 | pub use navigation_target::NavigationTarget; |
16 | pub(crate) use navigation_target::{ToNav, TryToNav}; | 8 | pub(crate) use navigation_target::{ToNav, TryToNav}; |
17 | pub(crate) use short_label::ShortLabel; | 9 | pub(crate) use short_label::ShortLabel; |
18 | 10 | ||
19 | pub(crate) fn function_declaration(node: &ast::Fn) -> String { | 11 | pub(crate) use syntax::display::{function_declaration, macro_label}; |
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.generic_param_list() { | ||
41 | format_to!(buf, "{}", type_params); | ||
42 | } | ||
43 | if let Some(param_list) = node.param_list() { | ||
44 | let params: Vec<String> = param_list | ||
45 | .self_param() | ||
46 | .into_iter() | ||
47 | .map(|self_param| self_param.to_string()) | ||
48 | .chain(param_list.params().map(|param| param.to_string())) | ||
49 | .collect(); | ||
50 | // Useful to inline parameters | ||
51 | format_to!(buf, "({})", params.join(", ")); | ||
52 | } | ||
53 | if let Some(ret_type) = node.ret_type() { | ||
54 | if ret_type.ty().is_some() { | ||
55 | format_to!(buf, " {}", ret_type); | ||
56 | } | ||
57 | } | ||
58 | if let Some(where_clause) = node.where_clause() { | ||
59 | format_to!(buf, "\n{}", where_clause); | ||
60 | } | ||
61 | buf | ||
62 | } | ||
63 | |||
64 | pub(crate) fn const_label(node: &ast::Const) -> String { | ||
65 | let label: String = node | ||
66 | .syntax() | ||
67 | .children_with_tokens() | ||
68 | .filter(|child| !(child.kind() == COMMENT || child.kind() == ATTR)) | ||
69 | .map(|node| node.to_string()) | ||
70 | .collect(); | ||
71 | |||
72 | label.trim().to_owned() | ||
73 | } | ||
74 | |||
75 | pub(crate) fn type_label(node: &ast::TypeAlias) -> String { | ||
76 | let label: String = node | ||
77 | .syntax() | ||
78 | .children_with_tokens() | ||
79 | .filter(|child| !(child.kind() == COMMENT || child.kind() == ATTR)) | ||
80 | .map(|node| node.to_string()) | ||
81 | .collect(); | ||
82 | |||
83 | label.trim().to_owned() | ||
84 | } | ||
85 | |||
86 | pub(crate) fn macro_label(node: &ast::MacroCall) -> String { | ||
87 | let name = node.name().map(|name| name.syntax().text().to_string()).unwrap_or_default(); | ||
88 | let vis = if node.has_atom_attr("macro_export") { "#[macro_export]\n" } else { "" }; | ||
89 | format!("{}macro_rules! {}", vis, name) | ||
90 | } | ||