aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src/file_structure.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide/src/file_structure.rs')
-rw-r--r--crates/ra_ide/src/file_structure.rs76
1 files changed, 33 insertions, 43 deletions
diff --git a/crates/ra_ide/src/file_structure.rs b/crates/ra_ide/src/file_structure.rs
index 1f6a3febf..ef368651a 100644
--- a/crates/ra_ide/src/file_structure.rs
+++ b/crates/ra_ide/src/file_structure.rs
@@ -1,5 +1,5 @@
1use ra_syntax::{ 1use ra_syntax::{
2 ast::{self, AttrsOwner, NameOwner, TypeAscriptionOwner, TypeParamsOwner}, 2 ast::{self, AttrsOwner, GenericParamsOwner, NameOwner},
3 match_ast, AstNode, SourceFile, SyntaxKind, SyntaxNode, TextRange, WalkEvent, 3 match_ast, AstNode, SourceFile, SyntaxKind, SyntaxNode, TextRange, WalkEvent,
4}; 4};
5 5
@@ -52,19 +52,12 @@ pub fn file_structure(file: &SourceFile) -> Vec<StructureNode> {
52 52
53fn structure_node(node: &SyntaxNode) -> Option<StructureNode> { 53fn structure_node(node: &SyntaxNode) -> Option<StructureNode> {
54 fn decl<N: NameOwner + AttrsOwner>(node: N) -> Option<StructureNode> { 54 fn decl<N: NameOwner + AttrsOwner>(node: N) -> Option<StructureNode> {
55 decl_with_detail(node, None) 55 decl_with_detail(&node, None)
56 }
57
58 fn decl_with_ascription<N: NameOwner + AttrsOwner + TypeAscriptionOwner>(
59 node: N,
60 ) -> Option<StructureNode> {
61 let ty = node.ascribed_type();
62 decl_with_type_ref(node, ty)
63 } 56 }
64 57
65 fn decl_with_type_ref<N: NameOwner + AttrsOwner>( 58 fn decl_with_type_ref<N: NameOwner + AttrsOwner>(
66 node: N, 59 node: &N,
67 type_ref: Option<ast::TypeRef>, 60 type_ref: Option<ast::Type>,
68 ) -> Option<StructureNode> { 61 ) -> Option<StructureNode> {
69 let detail = type_ref.map(|type_ref| { 62 let detail = type_ref.map(|type_ref| {
70 let mut detail = String::new(); 63 let mut detail = String::new();
@@ -75,7 +68,7 @@ fn structure_node(node: &SyntaxNode) -> Option<StructureNode> {
75 } 68 }
76 69
77 fn decl_with_detail<N: NameOwner + AttrsOwner>( 70 fn decl_with_detail<N: NameOwner + AttrsOwner>(
78 node: N, 71 node: &N,
79 detail: Option<String>, 72 detail: Option<String>,
80 ) -> Option<StructureNode> { 73 ) -> Option<StructureNode> {
81 let name = node.name()?; 74 let name = node.name()?;
@@ -111,9 +104,9 @@ fn structure_node(node: &SyntaxNode) -> Option<StructureNode> {
111 104
112 match_ast! { 105 match_ast! {
113 match node { 106 match node {
114 ast::FnDef(it) => { 107 ast::Fn(it) => {
115 let mut detail = String::from("fn"); 108 let mut detail = String::from("fn");
116 if let Some(type_param_list) = it.type_param_list() { 109 if let Some(type_param_list) = it.generic_param_list() {
117 collapse_ws(type_param_list.syntax(), &mut detail); 110 collapse_ws(type_param_list.syntax(), &mut detail);
118 } 111 }
119 if let Some(param_list) = it.param_list() { 112 if let Some(param_list) = it.param_list() {
@@ -124,22 +117,19 @@ fn structure_node(node: &SyntaxNode) -> Option<StructureNode> {
124 collapse_ws(ret_type.syntax(), &mut detail); 117 collapse_ws(ret_type.syntax(), &mut detail);
125 } 118 }
126 119
127 decl_with_detail(it, Some(detail)) 120 decl_with_detail(&it, Some(detail))
128 }, 121 },
129 ast::StructDef(it) => decl(it), 122 ast::Struct(it) => decl(it),
130 ast::UnionDef(it) => decl(it), 123 ast::Union(it) => decl(it),
131 ast::EnumDef(it) => decl(it), 124 ast::Enum(it) => decl(it),
132 ast::EnumVariant(it) => decl(it), 125 ast::Variant(it) => decl(it),
133 ast::TraitDef(it) => decl(it), 126 ast::Trait(it) => decl(it),
134 ast::Module(it) => decl(it), 127 ast::Module(it) => decl(it),
135 ast::TypeAliasDef(it) => { 128 ast::TypeAlias(it) => decl_with_type_ref(&it, it.ty()),
136 let ty = it.type_ref(); 129 ast::RecordField(it) => decl_with_type_ref(&it, it.ty()),
137 decl_with_type_ref(it, ty) 130 ast::Const(it) => decl_with_type_ref(&it, it.ty()),
138 }, 131 ast::Static(it) => decl_with_type_ref(&it, it.ty()),
139 ast::RecordFieldDef(it) => decl_with_ascription(it), 132 ast::Impl(it) => {
140 ast::ConstDef(it) => decl_with_ascription(it),
141 ast::StaticDef(it) => decl_with_ascription(it),
142 ast::ImplDef(it) => {
143 let target_type = it.target_type()?; 133 let target_type = it.target_type()?;
144 let target_trait = it.target_trait(); 134 let target_trait = it.target_trait();
145 let label = match target_trait { 135 let label = match target_trait {
@@ -238,7 +228,7 @@ fn very_obsolete() {}
238 label: "Foo", 228 label: "Foo",
239 navigation_range: 8..11, 229 navigation_range: 8..11,
240 node_range: 1..26, 230 node_range: 1..26,
241 kind: STRUCT_DEF, 231 kind: STRUCT,
242 detail: None, 232 detail: None,
243 deprecated: false, 233 deprecated: false,
244 }, 234 },
@@ -249,7 +239,7 @@ fn very_obsolete() {}
249 label: "x", 239 label: "x",
250 navigation_range: 18..19, 240 navigation_range: 18..19,
251 node_range: 18..24, 241 node_range: 18..24,
252 kind: RECORD_FIELD_DEF, 242 kind: RECORD_FIELD,
253 detail: Some( 243 detail: Some(
254 "i32", 244 "i32",
255 ), 245 ),
@@ -271,7 +261,7 @@ fn very_obsolete() {}
271 label: "bar1", 261 label: "bar1",
272 navigation_range: 43..47, 262 navigation_range: 43..47,
273 node_range: 40..52, 263 node_range: 40..52,
274 kind: FN_DEF, 264 kind: FN,
275 detail: Some( 265 detail: Some(
276 "fn()", 266 "fn()",
277 ), 267 ),
@@ -284,7 +274,7 @@ fn very_obsolete() {}
284 label: "bar2", 274 label: "bar2",
285 navigation_range: 60..64, 275 navigation_range: 60..64,
286 node_range: 57..81, 276 node_range: 57..81,
287 kind: FN_DEF, 277 kind: FN,
288 detail: Some( 278 detail: Some(
289 "fn<T>(t: T) -> T", 279 "fn<T>(t: T) -> T",
290 ), 280 ),
@@ -297,7 +287,7 @@ fn very_obsolete() {}
297 label: "bar3", 287 label: "bar3",
298 navigation_range: 89..93, 288 navigation_range: 89..93,
299 node_range: 86..156, 289 node_range: 86..156,
300 kind: FN_DEF, 290 kind: FN,
301 detail: Some( 291 detail: Some(
302 "fn<A, B>(a: A, b: B) -> Vec< u32 >", 292 "fn<A, B>(a: A, b: B) -> Vec< u32 >",
303 ), 293 ),
@@ -308,7 +298,7 @@ fn very_obsolete() {}
308 label: "E", 298 label: "E",
309 navigation_range: 165..166, 299 navigation_range: 165..166,
310 node_range: 160..180, 300 node_range: 160..180,
311 kind: ENUM_DEF, 301 kind: ENUM,
312 detail: None, 302 detail: None,
313 deprecated: false, 303 deprecated: false,
314 }, 304 },
@@ -319,7 +309,7 @@ fn very_obsolete() {}
319 label: "X", 309 label: "X",
320 navigation_range: 169..170, 310 navigation_range: 169..170,
321 node_range: 169..170, 311 node_range: 169..170,
322 kind: ENUM_VARIANT, 312 kind: VARIANT,
323 detail: None, 313 detail: None,
324 deprecated: false, 314 deprecated: false,
325 }, 315 },
@@ -330,7 +320,7 @@ fn very_obsolete() {}
330 label: "Y", 320 label: "Y",
331 navigation_range: 172..173, 321 navigation_range: 172..173,
332 node_range: 172..178, 322 node_range: 172..178,
333 kind: ENUM_VARIANT, 323 kind: VARIANT,
334 detail: None, 324 detail: None,
335 deprecated: false, 325 deprecated: false,
336 }, 326 },
@@ -339,7 +329,7 @@ fn very_obsolete() {}
339 label: "T", 329 label: "T",
340 navigation_range: 186..187, 330 navigation_range: 186..187,
341 node_range: 181..193, 331 node_range: 181..193,
342 kind: TYPE_ALIAS_DEF, 332 kind: TYPE_ALIAS,
343 detail: Some( 333 detail: Some(
344 "()", 334 "()",
345 ), 335 ),
@@ -350,7 +340,7 @@ fn very_obsolete() {}
350 label: "S", 340 label: "S",
351 navigation_range: 201..202, 341 navigation_range: 201..202,
352 node_range: 194..213, 342 node_range: 194..213,
353 kind: STATIC_DEF, 343 kind: STATIC,
354 detail: Some( 344 detail: Some(
355 "i32", 345 "i32",
356 ), 346 ),
@@ -361,7 +351,7 @@ fn very_obsolete() {}
361 label: "C", 351 label: "C",
362 navigation_range: 220..221, 352 navigation_range: 220..221,
363 node_range: 214..232, 353 node_range: 214..232,
364 kind: CONST_DEF, 354 kind: CONST,
365 detail: Some( 355 detail: Some(
366 "i32", 356 "i32",
367 ), 357 ),
@@ -372,7 +362,7 @@ fn very_obsolete() {}
372 label: "impl E", 362 label: "impl E",
373 navigation_range: 239..240, 363 navigation_range: 239..240,
374 node_range: 234..243, 364 node_range: 234..243,
375 kind: IMPL_DEF, 365 kind: IMPL,
376 detail: None, 366 detail: None,
377 deprecated: false, 367 deprecated: false,
378 }, 368 },
@@ -381,7 +371,7 @@ fn very_obsolete() {}
381 label: "impl fmt::Debug for E", 371 label: "impl fmt::Debug for E",
382 navigation_range: 265..266, 372 navigation_range: 265..266,
383 node_range: 245..269, 373 node_range: 245..269,
384 kind: IMPL_DEF, 374 kind: IMPL,
385 detail: None, 375 detail: None,
386 deprecated: false, 376 deprecated: false,
387 }, 377 },
@@ -417,7 +407,7 @@ fn very_obsolete() {}
417 label: "obsolete", 407 label: "obsolete",
418 navigation_range: 428..436, 408 navigation_range: 428..436,
419 node_range: 411..441, 409 node_range: 411..441,
420 kind: FN_DEF, 410 kind: FN,
421 detail: Some( 411 detail: Some(
422 "fn()", 412 "fn()",
423 ), 413 ),
@@ -428,7 +418,7 @@ fn very_obsolete() {}
428 label: "very_obsolete", 418 label: "very_obsolete",
429 navigation_range: 481..494, 419 navigation_range: 481..494,
430 node_range: 443..499, 420 node_range: 443..499,
431 kind: FN_DEF, 421 kind: FN,
432 detail: Some( 422 detail: Some(
433 "fn()", 423 "fn()",
434 ), 424 ),