aboutsummaryrefslogtreecommitdiff
path: root/crates/ide/src/display/short_label.rs
diff options
context:
space:
mode:
authorLukas Wirth <[email protected]>2021-03-16 14:44:31 +0000
committerLukas Wirth <[email protected]>2021-03-16 14:44:31 +0000
commit4628d94e749f05a12ca51548a2c9afa2cc44ea84 (patch)
tree21ea79493d6ae9ced12e73adc4398495e53108a5 /crates/ide/src/display/short_label.rs
parentb4ed3e1551f828d44dcd8e0caf08420438e5eb1a (diff)
Remove ShortLabel
Diffstat (limited to 'crates/ide/src/display/short_label.rs')
-rw-r--r--crates/ide/src/display/short_label.rs128
1 files changed, 0 insertions, 128 deletions
diff --git a/crates/ide/src/display/short_label.rs b/crates/ide/src/display/short_label.rs
deleted file mode 100644
index 2df9266b4..000000000
--- a/crates/ide/src/display/short_label.rs
+++ /dev/null
@@ -1,128 +0,0 @@
1//! FIXME: write short doc here
2
3use stdx::format_to;
4use syntax::ast::{self, AstNode, NameOwner, VisibilityOwner};
5
6pub(crate) trait ShortLabel {
7 fn short_label(&self) -> Option<String>;
8}
9
10impl ShortLabel for ast::Fn {
11 fn short_label(&self) -> Option<String> {
12 Some(crate::display::function_declaration(self))
13 }
14}
15
16impl ShortLabel for ast::Struct {
17 fn short_label(&self) -> Option<String> {
18 short_label_from_node(self, "struct ")
19 }
20}
21
22impl ShortLabel for ast::Union {
23 fn short_label(&self) -> Option<String> {
24 short_label_from_node(self, "union ")
25 }
26}
27
28impl ShortLabel for ast::Enum {
29 fn short_label(&self) -> Option<String> {
30 short_label_from_node(self, "enum ")
31 }
32}
33
34impl 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
44impl ShortLabel for ast::Module {
45 fn short_label(&self) -> Option<String> {
46 short_label_from_node(self, "mod ")
47 }
48}
49
50impl ShortLabel for ast::SourceFile {
51 fn short_label(&self) -> Option<String> {
52 None
53 }
54}
55
56impl ShortLabel for ast::BlockExpr {
57 fn short_label(&self) -> Option<String> {
58 None
59 }
60}
61
62impl ShortLabel for ast::TypeAlias {
63 fn short_label(&self) -> Option<String> {
64 let mut buf = short_label_from_node(self, "type ")?;
65 if let Some(type_ref) = self.ty() {
66 format_to!(buf, " = {}", type_ref.syntax());
67 }
68 Some(buf)
69 }
70}
71
72impl ShortLabel for ast::Const {
73 fn short_label(&self) -> Option<String> {
74 short_label_from_ty(self, self.ty(), "const ")
75 }
76}
77
78impl ShortLabel for ast::Static {
79 fn short_label(&self) -> Option<String> {
80 short_label_from_ty(self, self.ty(), "static ")
81 }
82}
83
84impl ShortLabel for ast::RecordField {
85 fn short_label(&self) -> Option<String> {
86 short_label_from_ty(self, self.ty(), "")
87 }
88}
89
90impl ShortLabel for ast::Variant {
91 fn short_label(&self) -> Option<String> {
92 Some(self.name()?.text().to_string())
93 }
94}
95
96impl ShortLabel for ast::ConstParam {
97 fn short_label(&self) -> Option<String> {
98 let mut buf = "const ".to_owned();
99 buf.push_str(self.name()?.text());
100 if let Some(type_ref) = self.ty() {
101 format_to!(buf, ": {}", type_ref.syntax());
102 }
103 Some(buf)
104 }
105}
106
107fn short_label_from_ty<T>(node: &T, ty: Option<ast::Type>, prefix: &str) -> Option<String>
108where
109 T: NameOwner + VisibilityOwner,
110{
111 let mut buf = short_label_from_node(node, prefix)?;
112
113 if let Some(type_ref) = ty {
114 format_to!(buf, ": {}", type_ref.syntax());
115 }
116
117 Some(buf)
118}
119
120fn short_label_from_node<T>(node: &T, label: &str) -> Option<String>
121where
122 T: NameOwner + VisibilityOwner,
123{
124 let mut buf = node.visibility().map(|v| format!("{} ", v.syntax())).unwrap_or_default();
125 buf.push_str(label);
126 buf.push_str(node.name()?.text());
127 Some(buf)
128}