aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src
diff options
context:
space:
mode:
authorEdwin Cheng <[email protected]>2019-06-09 20:28:53 +0100
committerEdwin Cheng <[email protected]>2019-06-09 20:28:53 +0100
commit41cb3fd7587f418ad18b6a3672211e0bfa304cfb (patch)
tree45326ded696223bab885bde3fbef5aaefae1f407 /crates/ra_ide_api/src
parent358ad0efca0fe76b040b47d199e166feb6128ac0 (diff)
Rename Description to ShortLabel
Diffstat (limited to 'crates/ra_ide_api/src')
-rw-r--r--crates/ra_ide_api/src/display.rs4
-rw-r--r--crates/ra_ide_api/src/display/description.rs92
-rw-r--r--crates/ra_ide_api/src/display/navigation_target.rs56
-rw-r--r--crates/ra_ide_api/src/display/short_label.rs92
-rw-r--r--crates/ra_ide_api/src/goto_definition.rs22
5 files changed, 133 insertions, 133 deletions
diff --git a/crates/ra_ide_api/src/display.rs b/crates/ra_ide_api/src/display.rs
index 313415610..7a8734a75 100644
--- a/crates/ra_ide_api/src/display.rs
+++ b/crates/ra_ide_api/src/display.rs
@@ -4,7 +4,7 @@
4mod function_signature; 4mod function_signature;
5mod navigation_target; 5mod navigation_target;
6mod structure; 6mod structure;
7mod description; 7mod short_label;
8 8
9use ra_syntax::{ast::{self, AstNode, TypeParamsOwner}, SyntaxKind::{ATTR, COMMENT}}; 9use ra_syntax::{ast::{self, AstNode, TypeParamsOwner}, SyntaxKind::{ATTR, COMMENT}};
10 10
@@ -12,7 +12,7 @@ pub use navigation_target::NavigationTarget;
12pub use structure::{StructureNode, file_structure}; 12pub use structure::{StructureNode, file_structure};
13pub use function_signature::FunctionSignature; 13pub use function_signature::FunctionSignature;
14 14
15pub(crate) use description::Description; 15pub(crate) use short_label::ShortLabel;
16 16
17pub(crate) fn function_label(node: &ast::FnDef) -> String { 17pub(crate) fn function_label(node: &ast::FnDef) -> String {
18 FunctionSignature::from(node).to_string() 18 FunctionSignature::from(node).to_string()
diff --git a/crates/ra_ide_api/src/display/description.rs b/crates/ra_ide_api/src/display/description.rs
deleted file mode 100644
index 4f6b0a858..000000000
--- a/crates/ra_ide_api/src/display/description.rs
+++ /dev/null
@@ -1,92 +0,0 @@
1use ra_syntax::{
2 ast::{self, NameOwner, VisibilityOwner, TypeAscriptionOwner, AstNode},
3};
4
5pub(crate) trait Description {
6 fn description(&self) -> Option<String>;
7}
8
9impl Description for ast::FnDef {
10 fn description(&self) -> Option<String> {
11 Some(crate::display::function_label(self))
12 }
13}
14
15impl Description for ast::StructDef {
16 fn description(&self) -> Option<String> {
17 description_from_node(self, "struct ")
18 }
19}
20
21impl Description for ast::EnumDef {
22 fn description(&self) -> Option<String> {
23 description_from_node(self, "enum ")
24 }
25}
26
27impl Description for ast::TraitDef {
28 fn description(&self) -> Option<String> {
29 description_from_node(self, "trait ")
30 }
31}
32
33impl Description for ast::Module {
34 fn description(&self) -> Option<String> {
35 description_from_node(self, "mod ")
36 }
37}
38
39impl Description for ast::TypeAliasDef {
40 fn description(&self) -> Option<String> {
41 description_from_node(self, "type ")
42 }
43}
44
45impl Description for ast::ConstDef {
46 fn description(&self) -> Option<String> {
47 description_from_ascribed_node(self, "const ")
48 }
49}
50
51impl Description for ast::StaticDef {
52 fn description(&self) -> Option<String> {
53 description_from_ascribed_node(self, "static ")
54 }
55}
56
57impl Description for ast::NamedFieldDef {
58 fn description(&self) -> Option<String> {
59 description_from_ascribed_node(self, "")
60 }
61}
62
63impl Description for ast::EnumVariant {
64 fn description(&self) -> Option<String> {
65 Some(self.name()?.text().to_string())
66 }
67}
68
69fn description_from_ascribed_node<T>(node: &T, prefix: &str) -> Option<String>
70where
71 T: NameOwner + VisibilityOwner + TypeAscriptionOwner,
72{
73 let mut string = description_from_node(node, prefix)?;
74
75 if let Some(type_ref) = node.ascribed_type() {
76 string.push_str(": ");
77 type_ref.syntax().text().push_to(&mut string);
78 }
79
80 Some(string)
81}
82
83fn description_from_node<T>(node: &T, label: &str) -> Option<String>
84where
85 T: NameOwner + VisibilityOwner,
86{
87 let mut string =
88 node.visibility().map(|v| format!("{} ", v.syntax().text())).unwrap_or_default();
89 string.push_str(label);
90 string.push_str(node.name()?.text().as_str());
91 Some(string)
92}
diff --git a/crates/ra_ide_api/src/display/navigation_target.rs b/crates/ra_ide_api/src/display/navigation_target.rs
index f441ae943..9b17d6adc 100644
--- a/crates/ra_ide_api/src/display/navigation_target.rs
+++ b/crates/ra_ide_api/src/display/navigation_target.rs
@@ -8,7 +8,7 @@ use ra_syntax::{
8use hir::{ModuleSource, FieldSource, ImplItem}; 8use hir::{ModuleSource, FieldSource, ImplItem};
9 9
10use crate::{FileSymbol, db::RootDatabase}; 10use crate::{FileSymbol, db::RootDatabase};
11use super::description::Description; 11use super::short_label::ShortLabel;
12 12
13/// `NavigationTarget` represents and element in the editor's UI which you can 13/// `NavigationTarget` represents and element in the editor's UI which you can
14/// click on to navigate to a particular piece of code. 14/// click on to navigate to a particular piece of code.
@@ -142,7 +142,7 @@ impl NavigationTarget {
142 None, 142 None,
143 node.syntax(), 143 node.syntax(),
144 node.doc_comment_text(), 144 node.doc_comment_text(),
145 node.description(), 145 node.short_label(),
146 ), 146 ),
147 } 147 }
148 } 148 }
@@ -157,7 +157,7 @@ impl NavigationTarget {
157 None, 157 None,
158 source.syntax(), 158 source.syntax(),
159 source.doc_comment_text(), 159 source.doc_comment_text(),
160 source.description(), 160 source.short_label(),
161 ); 161 );
162 } 162 }
163 NavigationTarget::from_module(db, module) 163 NavigationTarget::from_module(db, module)
@@ -169,7 +169,7 @@ impl NavigationTarget {
169 file_id.original_file(db), 169 file_id.original_file(db),
170 &*fn_def, 170 &*fn_def,
171 fn_def.doc_comment_text(), 171 fn_def.doc_comment_text(),
172 fn_def.description(), 172 fn_def.short_label(),
173 ) 173 )
174 } 174 }
175 175
@@ -178,7 +178,7 @@ impl NavigationTarget {
178 let file_id = file_id.original_file(db); 178 let file_id = file_id.original_file(db);
179 match field { 179 match field {
180 FieldSource::Named(it) => { 180 FieldSource::Named(it) => {
181 NavigationTarget::from_named(file_id, &*it, it.doc_comment_text(), it.description()) 181 NavigationTarget::from_named(file_id, &*it, it.doc_comment_text(), it.short_label())
182 } 182 }
183 FieldSource::Pos(it) => { 183 FieldSource::Pos(it) => {
184 NavigationTarget::from_syntax(file_id, "".into(), None, it.syntax(), None, None) 184 NavigationTarget::from_syntax(file_id, "".into(), None, it.syntax(), None, None)
@@ -194,7 +194,7 @@ impl NavigationTarget {
194 file_id.original_file(db), 194 file_id.original_file(db),
195 &*node, 195 &*node,
196 node.doc_comment_text(), 196 node.doc_comment_text(),
197 node.description(), 197 node.short_label(),
198 ) 198 )
199 } 199 }
200 hir::AdtDef::Union(s) => { 200 hir::AdtDef::Union(s) => {
@@ -203,7 +203,7 @@ impl NavigationTarget {
203 file_id.original_file(db), 203 file_id.original_file(db),
204 &*node, 204 &*node,
205 node.doc_comment_text(), 205 node.doc_comment_text(),
206 node.description(), 206 node.short_label(),
207 ) 207 )
208 } 208 }
209 hir::AdtDef::Enum(s) => { 209 hir::AdtDef::Enum(s) => {
@@ -212,7 +212,7 @@ impl NavigationTarget {
212 file_id.original_file(db), 212 file_id.original_file(db),
213 &*node, 213 &*node,
214 node.doc_comment_text(), 214 node.doc_comment_text(),
215 node.description(), 215 node.short_label(),
216 ) 216 )
217 } 217 }
218 } 218 }
@@ -231,7 +231,7 @@ impl NavigationTarget {
231 file_id.original_file(db), 231 file_id.original_file(db),
232 &*node, 232 &*node,
233 node.doc_comment_text(), 233 node.doc_comment_text(),
234 node.description(), 234 node.short_label(),
235 ) 235 )
236 } 236 }
237 hir::ModuleDef::Union(s) => { 237 hir::ModuleDef::Union(s) => {
@@ -240,7 +240,7 @@ impl NavigationTarget {
240 file_id.original_file(db), 240 file_id.original_file(db),
241 &*node, 241 &*node,
242 node.doc_comment_text(), 242 node.doc_comment_text(),
243 node.description(), 243 node.short_label(),
244 ) 244 )
245 } 245 }
246 hir::ModuleDef::Const(s) => { 246 hir::ModuleDef::Const(s) => {
@@ -249,7 +249,7 @@ impl NavigationTarget {
249 file_id.original_file(db), 249 file_id.original_file(db),
250 &*node, 250 &*node,
251 node.doc_comment_text(), 251 node.doc_comment_text(),
252 node.description(), 252 node.short_label(),
253 ) 253 )
254 } 254 }
255 hir::ModuleDef::Static(s) => { 255 hir::ModuleDef::Static(s) => {
@@ -258,7 +258,7 @@ impl NavigationTarget {
258 file_id.original_file(db), 258 file_id.original_file(db),
259 &*node, 259 &*node,
260 node.doc_comment_text(), 260 node.doc_comment_text(),
261 node.description(), 261 node.short_label(),
262 ) 262 )
263 } 263 }
264 hir::ModuleDef::Enum(e) => { 264 hir::ModuleDef::Enum(e) => {
@@ -267,7 +267,7 @@ impl NavigationTarget {
267 file_id.original_file(db), 267 file_id.original_file(db),
268 &*node, 268 &*node,
269 node.doc_comment_text(), 269 node.doc_comment_text(),
270 node.description(), 270 node.short_label(),
271 ) 271 )
272 } 272 }
273 hir::ModuleDef::EnumVariant(var) => { 273 hir::ModuleDef::EnumVariant(var) => {
@@ -276,7 +276,7 @@ impl NavigationTarget {
276 file_id.original_file(db), 276 file_id.original_file(db),
277 &*node, 277 &*node,
278 node.doc_comment_text(), 278 node.doc_comment_text(),
279 node.description(), 279 node.short_label(),
280 ) 280 )
281 } 281 }
282 hir::ModuleDef::Trait(e) => { 282 hir::ModuleDef::Trait(e) => {
@@ -285,7 +285,7 @@ impl NavigationTarget {
285 file_id.original_file(db), 285 file_id.original_file(db),
286 &*node, 286 &*node,
287 node.doc_comment_text(), 287 node.doc_comment_text(),
288 node.description(), 288 node.short_label(),
289 ) 289 )
290 } 290 }
291 hir::ModuleDef::TypeAlias(e) => { 291 hir::ModuleDef::TypeAlias(e) => {
@@ -294,7 +294,7 @@ impl NavigationTarget {
294 file_id.original_file(db), 294 file_id.original_file(db),
295 &*node, 295 &*node,
296 node.doc_comment_text(), 296 node.doc_comment_text(),
297 node.description(), 297 node.short_label(),
298 ) 298 )
299 } 299 }
300 hir::ModuleDef::BuiltinType(..) => { 300 hir::ModuleDef::BuiltinType(..) => {
@@ -328,7 +328,7 @@ impl NavigationTarget {
328 file_id.original_file(db), 328 file_id.original_file(db),
329 &*node, 329 &*node,
330 node.doc_comment_text(), 330 node.doc_comment_text(),
331 node.description(), 331 node.short_label(),
332 ) 332 )
333 } 333 }
334 ImplItem::TypeAlias(a) => { 334 ImplItem::TypeAlias(a) => {
@@ -337,7 +337,7 @@ impl NavigationTarget {
337 file_id.original_file(db), 337 file_id.original_file(db),
338 &*node, 338 &*node,
339 node.doc_comment_text(), 339 node.doc_comment_text(),
340 node.description(), 340 node.short_label(),
341 ) 341 )
342 } 342 }
343 } 343 }
@@ -446,15 +446,15 @@ fn description_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> Option<Str
446 // FIXME: After type inference is done, add type information to improve the output 446 // FIXME: After type inference is done, add type information to improve the output
447 447
448 visitor() 448 visitor()
449 .visit(|node: &ast::FnDef| node.description()) 449 .visit(|node: &ast::FnDef| node.short_label())
450 .visit(|node: &ast::StructDef| node.description()) 450 .visit(|node: &ast::StructDef| node.short_label())
451 .visit(|node: &ast::EnumDef| node.description()) 451 .visit(|node: &ast::EnumDef| node.short_label())
452 .visit(|node: &ast::TraitDef| node.description()) 452 .visit(|node: &ast::TraitDef| node.short_label())
453 .visit(|node: &ast::Module| node.description()) 453 .visit(|node: &ast::Module| node.short_label())
454 .visit(|node: &ast::TypeAliasDef| node.description()) 454 .visit(|node: &ast::TypeAliasDef| node.short_label())
455 .visit(|node: &ast::ConstDef| node.description()) 455 .visit(|node: &ast::ConstDef| node.short_label())
456 .visit(|node: &ast::StaticDef| node.description()) 456 .visit(|node: &ast::StaticDef| node.short_label())
457 .visit(|node: &ast::NamedFieldDef| node.description()) 457 .visit(|node: &ast::NamedFieldDef| node.short_label())
458 .visit(|node: &ast::EnumVariant| node.description()) 458 .visit(|node: &ast::EnumVariant| node.short_label())
459 .accept(&node)? 459 .accept(&node)?
460} 460}
diff --git a/crates/ra_ide_api/src/display/short_label.rs b/crates/ra_ide_api/src/display/short_label.rs
new file mode 100644
index 000000000..6acb2ab92
--- /dev/null
+++ b/crates/ra_ide_api/src/display/short_label.rs
@@ -0,0 +1,92 @@
1use ra_syntax::{
2 ast::{self, NameOwner, VisibilityOwner, TypeAscriptionOwner, AstNode},
3};
4
5pub(crate) trait ShortLabel {
6 fn short_label(&self) -> Option<String>;
7}
8
9impl ShortLabel for ast::FnDef {
10 fn short_label(&self) -> Option<String> {
11 Some(crate::display::function_label(self))
12 }
13}
14
15impl ShortLabel for ast::StructDef {
16 fn short_label(&self) -> Option<String> {
17 short_label_from_node(self, "struct ")
18 }
19}
20
21impl ShortLabel for ast::EnumDef {
22 fn short_label(&self) -> Option<String> {
23 short_label_from_node(self, "enum ")
24 }
25}
26
27impl ShortLabel for ast::TraitDef {
28 fn short_label(&self) -> Option<String> {
29 short_label_from_node(self, "trait ")
30 }
31}
32
33impl ShortLabel for ast::Module {
34 fn short_label(&self) -> Option<String> {
35 short_label_from_node(self, "mod ")
36 }
37}
38
39impl ShortLabel for ast::TypeAliasDef {
40 fn short_label(&self) -> Option<String> {
41 short_label_from_node(self, "type ")
42 }
43}
44
45impl ShortLabel for ast::ConstDef {
46 fn short_label(&self) -> Option<String> {
47 short_label_from_ascribed_node(self, "const ")
48 }
49}
50
51impl ShortLabel for ast::StaticDef {
52 fn short_label(&self) -> Option<String> {
53 short_label_from_ascribed_node(self, "static ")
54 }
55}
56
57impl ShortLabel for ast::NamedFieldDef {
58 fn short_label(&self) -> Option<String> {
59 short_label_from_ascribed_node(self, "")
60 }
61}
62
63impl ShortLabel for ast::EnumVariant {
64 fn short_label(&self) -> Option<String> {
65 Some(self.name()?.text().to_string())
66 }
67}
68
69fn short_label_from_ascribed_node<T>(node: &T, prefix: &str) -> Option<String>
70where
71 T: NameOwner + VisibilityOwner + TypeAscriptionOwner,
72{
73 let mut string = short_label_from_node(node, prefix)?;
74
75 if let Some(type_ref) = node.ascribed_type() {
76 string.push_str(": ");
77 type_ref.syntax().text().push_to(&mut string);
78 }
79
80 Some(string)
81}
82
83fn short_label_from_node<T>(node: &T, label: &str) -> Option<String>
84where
85 T: NameOwner + VisibilityOwner,
86{
87 let mut string =
88 node.visibility().map(|v| format!("{} ", v.syntax().text())).unwrap_or_default();
89 string.push_str(label);
90 string.push_str(node.name()?.text().as_str());
91 Some(string)
92}
diff --git a/crates/ra_ide_api/src/goto_definition.rs b/crates/ra_ide_api/src/goto_definition.rs
index 359fc2da1..325a5a4f3 100644
--- a/crates/ra_ide_api/src/goto_definition.rs
+++ b/crates/ra_ide_api/src/goto_definition.rs
@@ -13,7 +13,7 @@ use crate::{
13 db::RootDatabase, 13 db::RootDatabase,
14 RangeInfo, 14 RangeInfo,
15 name_ref_kind::{NameRefKind::*, classify_name_ref}, 15 name_ref_kind::{NameRefKind::*, classify_name_ref},
16 display::Description, 16 display::ShortLabel,
17}; 17};
18 18
19pub(crate) fn goto_definition( 19pub(crate) fn goto_definition(
@@ -116,34 +116,34 @@ pub(crate) fn name_definition(
116fn named_target(file_id: FileId, node: &SyntaxNode) -> Option<NavigationTarget> { 116fn named_target(file_id: FileId, node: &SyntaxNode) -> Option<NavigationTarget> {
117 visitor() 117 visitor()
118 .visit(|node: &ast::StructDef| { 118 .visit(|node: &ast::StructDef| {
119 NavigationTarget::from_named(file_id, node, node.doc_comment_text(), node.description()) 119 NavigationTarget::from_named(file_id, node, node.doc_comment_text(), node.short_label())
120 }) 120 })
121 .visit(|node: &ast::EnumDef| { 121 .visit(|node: &ast::EnumDef| {
122 NavigationTarget::from_named(file_id, node, node.doc_comment_text(), node.description()) 122 NavigationTarget::from_named(file_id, node, node.doc_comment_text(), node.short_label())
123 }) 123 })
124 .visit(|node: &ast::EnumVariant| { 124 .visit(|node: &ast::EnumVariant| {
125 NavigationTarget::from_named(file_id, node, node.doc_comment_text(), node.description()) 125 NavigationTarget::from_named(file_id, node, node.doc_comment_text(), node.short_label())
126 }) 126 })
127 .visit(|node: &ast::FnDef| { 127 .visit(|node: &ast::FnDef| {
128 NavigationTarget::from_named(file_id, node, node.doc_comment_text(), node.description()) 128 NavigationTarget::from_named(file_id, node, node.doc_comment_text(), node.short_label())
129 }) 129 })
130 .visit(|node: &ast::TypeAliasDef| { 130 .visit(|node: &ast::TypeAliasDef| {
131 NavigationTarget::from_named(file_id, node, node.doc_comment_text(), node.description()) 131 NavigationTarget::from_named(file_id, node, node.doc_comment_text(), node.short_label())
132 }) 132 })
133 .visit(|node: &ast::ConstDef| { 133 .visit(|node: &ast::ConstDef| {
134 NavigationTarget::from_named(file_id, node, node.doc_comment_text(), node.description()) 134 NavigationTarget::from_named(file_id, node, node.doc_comment_text(), node.short_label())
135 }) 135 })
136 .visit(|node: &ast::StaticDef| { 136 .visit(|node: &ast::StaticDef| {
137 NavigationTarget::from_named(file_id, node, node.doc_comment_text(), node.description()) 137 NavigationTarget::from_named(file_id, node, node.doc_comment_text(), node.short_label())
138 }) 138 })
139 .visit(|node: &ast::TraitDef| { 139 .visit(|node: &ast::TraitDef| {
140 NavigationTarget::from_named(file_id, node, node.doc_comment_text(), node.description()) 140 NavigationTarget::from_named(file_id, node, node.doc_comment_text(), node.short_label())
141 }) 141 })
142 .visit(|node: &ast::NamedFieldDef| { 142 .visit(|node: &ast::NamedFieldDef| {
143 NavigationTarget::from_named(file_id, node, node.doc_comment_text(), node.description()) 143 NavigationTarget::from_named(file_id, node, node.doc_comment_text(), node.short_label())
144 }) 144 })
145 .visit(|node: &ast::Module| { 145 .visit(|node: &ast::Module| {
146 NavigationTarget::from_named(file_id, node, node.doc_comment_text(), node.description()) 146 NavigationTarget::from_named(file_id, node, node.doc_comment_text(), node.short_label())
147 }) 147 })
148 .visit(|node: &ast::MacroCall| { 148 .visit(|node: &ast::MacroCall| {
149 NavigationTarget::from_named(file_id, node, node.doc_comment_text(), None) 149 NavigationTarget::from_named(file_id, node, node.doc_comment_text(), None)