diff options
Diffstat (limited to 'crates/ra_ide/src/display/short_label.rs')
-rw-r--r-- | crates/ra_ide/src/display/short_label.rs | 101 |
1 files changed, 0 insertions, 101 deletions
diff --git a/crates/ra_ide/src/display/short_label.rs b/crates/ra_ide/src/display/short_label.rs deleted file mode 100644 index bddf1bd47..000000000 --- a/crates/ra_ide/src/display/short_label.rs +++ /dev/null | |||
@@ -1,101 +0,0 @@ | |||
1 | //! FIXME: write short doc here | ||
2 | |||
3 | use ra_syntax::ast::{self, AstNode, NameOwner, VisibilityOwner}; | ||
4 | use stdx::format_to; | ||
5 | |||
6 | pub(crate) trait ShortLabel { | ||
7 | fn short_label(&self) -> Option<String>; | ||
8 | } | ||
9 | |||
10 | impl ShortLabel for ast::Fn { | ||
11 | fn short_label(&self) -> Option<String> { | ||
12 | Some(crate::display::function_declaration(self)) | ||
13 | } | ||
14 | } | ||
15 | |||
16 | impl ShortLabel for ast::Struct { | ||
17 | fn short_label(&self) -> Option<String> { | ||
18 | short_label_from_node(self, "struct ") | ||
19 | } | ||
20 | } | ||
21 | |||
22 | impl ShortLabel for ast::Union { | ||
23 | fn short_label(&self) -> Option<String> { | ||
24 | short_label_from_node(self, "union ") | ||
25 | } | ||
26 | } | ||
27 | |||
28 | impl ShortLabel for ast::Enum { | ||
29 | fn short_label(&self) -> Option<String> { | ||
30 | short_label_from_node(self, "enum ") | ||
31 | } | ||
32 | } | ||
33 | |||
34 | impl ShortLabel for ast::Trait { | ||
35 | fn short_label(&self) -> Option<String> { | ||
36 | if self.unsafe_token().is_some() { | ||
37 | short_label_from_node(self, "unsafe trait ") | ||
38 | } else { | ||
39 | short_label_from_node(self, "trait ") | ||
40 | } | ||
41 | } | ||
42 | } | ||
43 | |||
44 | impl ShortLabel for ast::Module { | ||
45 | fn short_label(&self) -> Option<String> { | ||
46 | short_label_from_node(self, "mod ") | ||
47 | } | ||
48 | } | ||
49 | |||
50 | impl ShortLabel for ast::TypeAlias { | ||
51 | fn short_label(&self) -> Option<String> { | ||
52 | short_label_from_node(self, "type ") | ||
53 | } | ||
54 | } | ||
55 | |||
56 | impl ShortLabel for ast::Const { | ||
57 | fn short_label(&self) -> Option<String> { | ||
58 | short_label_from_ty(self, self.ty(), "const ") | ||
59 | } | ||
60 | } | ||
61 | |||
62 | impl ShortLabel for ast::Static { | ||
63 | fn short_label(&self) -> Option<String> { | ||
64 | short_label_from_ty(self, self.ty(), "static ") | ||
65 | } | ||
66 | } | ||
67 | |||
68 | impl ShortLabel for ast::RecordField { | ||
69 | fn short_label(&self) -> Option<String> { | ||
70 | short_label_from_ty(self, self.ty(), "") | ||
71 | } | ||
72 | } | ||
73 | |||
74 | impl ShortLabel for ast::Variant { | ||
75 | fn short_label(&self) -> Option<String> { | ||
76 | Some(self.name()?.text().to_string()) | ||
77 | } | ||
78 | } | ||
79 | |||
80 | fn short_label_from_ty<T>(node: &T, ty: Option<ast::TypeRef>, prefix: &str) -> Option<String> | ||
81 | where | ||
82 | T: NameOwner + VisibilityOwner, | ||
83 | { | ||
84 | let mut buf = short_label_from_node(node, prefix)?; | ||
85 | |||
86 | if let Some(type_ref) = ty { | ||
87 | format_to!(buf, ": {}", type_ref.syntax()); | ||
88 | } | ||
89 | |||
90 | Some(buf) | ||
91 | } | ||
92 | |||
93 | fn short_label_from_node<T>(node: &T, label: &str) -> Option<String> | ||
94 | where | ||
95 | T: NameOwner + VisibilityOwner, | ||
96 | { | ||
97 | let mut buf = node.visibility().map(|v| format!("{} ", v.syntax())).unwrap_or_default(); | ||
98 | buf.push_str(label); | ||
99 | buf.push_str(node.name()?.text().as_str()); | ||
100 | Some(buf) | ||
101 | } | ||