diff options
Diffstat (limited to 'crates/ide/src')
-rw-r--r-- | crates/ide/src/annotations.rs | 16 | ||||
-rw-r--r-- | crates/ide/src/file_structure.rs | 126 | ||||
-rw-r--r-- | crates/ide/src/syntax_highlighting/tags.rs | 1 |
3 files changed, 94 insertions, 49 deletions
diff --git a/crates/ide/src/annotations.rs b/crates/ide/src/annotations.rs index 2e8e82b70..fd317874e 100644 --- a/crates/ide/src/annotations.rs +++ b/crates/ide/src/annotations.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | use hir::Semantics; | 1 | use hir::Semantics; |
2 | use ide_db::{ | 2 | use ide_db::{ |
3 | base_db::{FileId, FilePosition, FileRange, SourceDatabase}, | 3 | base_db::{FileId, FilePosition, FileRange, SourceDatabase}, |
4 | RootDatabase, SymbolKind, | 4 | RootDatabase, StructureNodeKind, SymbolKind, |
5 | }; | 5 | }; |
6 | use syntax::TextRange; | 6 | use syntax::TextRange; |
7 | 7 | ||
@@ -80,15 +80,17 @@ pub(crate) fn annotations( | |||
80 | .filter(|node| { | 80 | .filter(|node| { |
81 | matches!( | 81 | matches!( |
82 | node.kind, | 82 | node.kind, |
83 | SymbolKind::Trait | 83 | StructureNodeKind::SymbolKind(SymbolKind::Trait) |
84 | | SymbolKind::Struct | 84 | | StructureNodeKind::SymbolKind(SymbolKind::Struct) |
85 | | SymbolKind::Enum | 85 | | StructureNodeKind::SymbolKind(SymbolKind::Enum) |
86 | | SymbolKind::Union | 86 | | StructureNodeKind::SymbolKind(SymbolKind::Union) |
87 | | SymbolKind::Const | 87 | | StructureNodeKind::SymbolKind(SymbolKind::Const) |
88 | ) | 88 | ) |
89 | }) | 89 | }) |
90 | .for_each(|node| { | 90 | .for_each(|node| { |
91 | if config.annotate_impls && node.kind != SymbolKind::Const { | 91 | if config.annotate_impls |
92 | && node.kind != StructureNodeKind::SymbolKind(SymbolKind::Const) | ||
93 | { | ||
92 | annotations.push(Annotation { | 94 | annotations.push(Annotation { |
93 | range: node.node_range, | 95 | range: node.node_range, |
94 | kind: AnnotationKind::HasImpls { | 96 | kind: AnnotationKind::HasImpls { |
diff --git a/crates/ide/src/file_structure.rs b/crates/ide/src/file_structure.rs index c5ca6ff26..c21b3fa77 100644 --- a/crates/ide/src/file_structure.rs +++ b/crates/ide/src/file_structure.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | use ide_db::SymbolKind; | 1 | use ide_db::{StructureNodeKind, SymbolKind}; |
2 | use syntax::{ | 2 | use syntax::{ |
3 | ast::{self, AttrsOwner, GenericParamsOwner, NameOwner}, | 3 | ast::{self, AttrsOwner, GenericParamsOwner, NameOwner}, |
4 | match_ast, AstNode, AstToken, NodeOrToken, SourceFile, SyntaxNode, SyntaxToken, TextRange, | 4 | match_ast, AstNode, AstToken, NodeOrToken, SourceFile, SyntaxNode, SyntaxToken, TextRange, |
@@ -11,7 +11,7 @@ pub struct StructureNode { | |||
11 | pub label: String, | 11 | pub label: String, |
12 | pub navigation_range: TextRange, | 12 | pub navigation_range: TextRange, |
13 | pub node_range: TextRange, | 13 | pub node_range: TextRange, |
14 | pub kind: SymbolKind, | 14 | pub kind: StructureNodeKind, |
15 | pub detail: Option<String>, | 15 | pub detail: Option<String>, |
16 | pub deprecated: bool, | 16 | pub deprecated: bool, |
17 | } | 17 | } |
@@ -65,14 +65,14 @@ pub(crate) fn file_structure(file: &SourceFile) -> Vec<StructureNode> { | |||
65 | } | 65 | } |
66 | 66 | ||
67 | fn structure_node(node: &SyntaxNode) -> Option<StructureNode> { | 67 | fn structure_node(node: &SyntaxNode) -> Option<StructureNode> { |
68 | fn decl<N: NameOwner + AttrsOwner>(node: N, kind: SymbolKind) -> Option<StructureNode> { | 68 | fn decl<N: NameOwner + AttrsOwner>(node: N, kind: StructureNodeKind) -> Option<StructureNode> { |
69 | decl_with_detail(&node, None, kind) | 69 | decl_with_detail(&node, None, kind) |
70 | } | 70 | } |
71 | 71 | ||
72 | fn decl_with_type_ref<N: NameOwner + AttrsOwner>( | 72 | fn decl_with_type_ref<N: NameOwner + AttrsOwner>( |
73 | node: &N, | 73 | node: &N, |
74 | type_ref: Option<ast::Type>, | 74 | type_ref: Option<ast::Type>, |
75 | kind: SymbolKind, | 75 | kind: StructureNodeKind, |
76 | ) -> Option<StructureNode> { | 76 | ) -> Option<StructureNode> { |
77 | let detail = type_ref.map(|type_ref| { | 77 | let detail = type_ref.map(|type_ref| { |
78 | let mut detail = String::new(); | 78 | let mut detail = String::new(); |
@@ -85,7 +85,7 @@ fn structure_node(node: &SyntaxNode) -> Option<StructureNode> { | |||
85 | fn decl_with_detail<N: NameOwner + AttrsOwner>( | 85 | fn decl_with_detail<N: NameOwner + AttrsOwner>( |
86 | node: &N, | 86 | node: &N, |
87 | detail: Option<String>, | 87 | detail: Option<String>, |
88 | kind: SymbolKind, | 88 | kind: StructureNodeKind, |
89 | ) -> Option<StructureNode> { | 89 | ) -> Option<StructureNode> { |
90 | let name = node.name()?; | 90 | let name = node.name()?; |
91 | 91 | ||
@@ -133,18 +133,18 @@ fn structure_node(node: &SyntaxNode) -> Option<StructureNode> { | |||
133 | collapse_ws(ret_type.syntax(), &mut detail); | 133 | collapse_ws(ret_type.syntax(), &mut detail); |
134 | } | 134 | } |
135 | 135 | ||
136 | decl_with_detail(&it, Some(detail), SymbolKind::Function) | 136 | decl_with_detail(&it, Some(detail), StructureNodeKind::SymbolKind(SymbolKind::Function)) |
137 | }, | 137 | }, |
138 | ast::Struct(it) => decl(it, SymbolKind::Struct), | 138 | ast::Struct(it) => decl(it, StructureNodeKind::SymbolKind(SymbolKind::Struct)), |
139 | ast::Union(it) => decl(it, SymbolKind::Union), | 139 | ast::Union(it) => decl(it, StructureNodeKind::SymbolKind(SymbolKind::Union)), |
140 | ast::Enum(it) => decl(it, SymbolKind::Enum), | 140 | ast::Enum(it) => decl(it, StructureNodeKind::SymbolKind(SymbolKind::Enum)), |
141 | ast::Variant(it) => decl(it, SymbolKind::Variant), | 141 | ast::Variant(it) => decl(it, StructureNodeKind::SymbolKind(SymbolKind::Variant)), |
142 | ast::Trait(it) => decl(it, SymbolKind::Trait), | 142 | ast::Trait(it) => decl(it, StructureNodeKind::SymbolKind(SymbolKind::Trait)), |
143 | ast::Module(it) => decl(it, SymbolKind::Module), | 143 | ast::Module(it) => decl(it, StructureNodeKind::SymbolKind(SymbolKind::Module)), |
144 | ast::TypeAlias(it) => decl_with_type_ref(&it, it.ty(), SymbolKind::TypeAlias), | 144 | ast::TypeAlias(it) => decl_with_type_ref(&it, it.ty(), StructureNodeKind::SymbolKind(SymbolKind::TypeAlias)), |
145 | ast::RecordField(it) => decl_with_type_ref(&it, it.ty(), SymbolKind::Field), | 145 | ast::RecordField(it) => decl_with_type_ref(&it, it.ty(), StructureNodeKind::SymbolKind(SymbolKind::Field)), |
146 | ast::Const(it) => decl_with_type_ref(&it, it.ty(), SymbolKind::Const), | 146 | ast::Const(it) => decl_with_type_ref(&it, it.ty(), StructureNodeKind::SymbolKind(SymbolKind::Const)), |
147 | ast::Static(it) => decl_with_type_ref(&it, it.ty(), SymbolKind::Static), | 147 | ast::Static(it) => decl_with_type_ref(&it, it.ty(), StructureNodeKind::SymbolKind(SymbolKind::Static)), |
148 | ast::Impl(it) => { | 148 | ast::Impl(it) => { |
149 | let target_type = it.self_ty()?; | 149 | let target_type = it.self_ty()?; |
150 | let target_trait = it.trait_(); | 150 | let target_trait = it.trait_(); |
@@ -160,13 +160,13 @@ fn structure_node(node: &SyntaxNode) -> Option<StructureNode> { | |||
160 | label, | 160 | label, |
161 | navigation_range: target_type.syntax().text_range(), | 161 | navigation_range: target_type.syntax().text_range(), |
162 | node_range: it.syntax().text_range(), | 162 | node_range: it.syntax().text_range(), |
163 | kind: SymbolKind::Impl, | 163 | kind: StructureNodeKind::SymbolKind(SymbolKind::Impl), |
164 | detail: None, | 164 | detail: None, |
165 | deprecated: false, | 165 | deprecated: false, |
166 | }; | 166 | }; |
167 | Some(node) | 167 | Some(node) |
168 | }, | 168 | }, |
169 | ast::MacroRules(it) => decl(it, SymbolKind::Macro), | 169 | ast::MacroRules(it) => decl(it, StructureNodeKind::SymbolKind(SymbolKind::Macro)), |
170 | _ => None, | 170 | _ => None, |
171 | } | 171 | } |
172 | } | 172 | } |
@@ -182,7 +182,7 @@ fn structure_token(token: SyntaxToken) -> Option<StructureNode> { | |||
182 | label: region_name.to_string(), | 182 | label: region_name.to_string(), |
183 | navigation_range: comment.syntax().text_range(), | 183 | navigation_range: comment.syntax().text_range(), |
184 | node_range: comment.syntax().text_range(), | 184 | node_range: comment.syntax().text_range(), |
185 | kind: SymbolKind::Region, | 185 | kind: StructureNodeKind::Region, |
186 | detail: None, | 186 | detail: None, |
187 | deprecated: false, | 187 | deprecated: false, |
188 | }); | 188 | }); |
@@ -268,7 +268,9 @@ fn g() {} | |||
268 | label: "Foo", | 268 | label: "Foo", |
269 | navigation_range: 8..11, | 269 | navigation_range: 8..11, |
270 | node_range: 1..26, | 270 | node_range: 1..26, |
271 | kind: Struct, | 271 | kind: SymbolKind( |
272 | Struct, | ||
273 | ), | ||
272 | detail: None, | 274 | detail: None, |
273 | deprecated: false, | 275 | deprecated: false, |
274 | }, | 276 | }, |
@@ -279,7 +281,9 @@ fn g() {} | |||
279 | label: "x", | 281 | label: "x", |
280 | navigation_range: 18..19, | 282 | navigation_range: 18..19, |
281 | node_range: 18..24, | 283 | node_range: 18..24, |
282 | kind: Field, | 284 | kind: SymbolKind( |
285 | Field, | ||
286 | ), | ||
283 | detail: Some( | 287 | detail: Some( |
284 | "i32", | 288 | "i32", |
285 | ), | 289 | ), |
@@ -290,7 +294,9 @@ fn g() {} | |||
290 | label: "m", | 294 | label: "m", |
291 | navigation_range: 32..33, | 295 | navigation_range: 32..33, |
292 | node_range: 28..158, | 296 | node_range: 28..158, |
293 | kind: Module, | 297 | kind: SymbolKind( |
298 | Module, | ||
299 | ), | ||
294 | detail: None, | 300 | detail: None, |
295 | deprecated: false, | 301 | deprecated: false, |
296 | }, | 302 | }, |
@@ -301,7 +307,9 @@ fn g() {} | |||
301 | label: "bar1", | 307 | label: "bar1", |
302 | navigation_range: 43..47, | 308 | navigation_range: 43..47, |
303 | node_range: 40..52, | 309 | node_range: 40..52, |
304 | kind: Function, | 310 | kind: SymbolKind( |
311 | Function, | ||
312 | ), | ||
305 | detail: Some( | 313 | detail: Some( |
306 | "fn()", | 314 | "fn()", |
307 | ), | 315 | ), |
@@ -314,7 +322,9 @@ fn g() {} | |||
314 | label: "bar2", | 322 | label: "bar2", |
315 | navigation_range: 60..64, | 323 | navigation_range: 60..64, |
316 | node_range: 57..81, | 324 | node_range: 57..81, |
317 | kind: Function, | 325 | kind: SymbolKind( |
326 | Function, | ||
327 | ), | ||
318 | detail: Some( | 328 | detail: Some( |
319 | "fn<T>(t: T) -> T", | 329 | "fn<T>(t: T) -> T", |
320 | ), | 330 | ), |
@@ -327,7 +337,9 @@ fn g() {} | |||
327 | label: "bar3", | 337 | label: "bar3", |
328 | navigation_range: 89..93, | 338 | navigation_range: 89..93, |
329 | node_range: 86..156, | 339 | node_range: 86..156, |
330 | kind: Function, | 340 | kind: SymbolKind( |
341 | Function, | ||
342 | ), | ||
331 | detail: Some( | 343 | detail: Some( |
332 | "fn<A, B>(a: A, b: B) -> Vec< u32 >", | 344 | "fn<A, B>(a: A, b: B) -> Vec< u32 >", |
333 | ), | 345 | ), |
@@ -338,7 +350,9 @@ fn g() {} | |||
338 | label: "E", | 350 | label: "E", |
339 | navigation_range: 165..166, | 351 | navigation_range: 165..166, |
340 | node_range: 160..180, | 352 | node_range: 160..180, |
341 | kind: Enum, | 353 | kind: SymbolKind( |
354 | Enum, | ||
355 | ), | ||
342 | detail: None, | 356 | detail: None, |
343 | deprecated: false, | 357 | deprecated: false, |
344 | }, | 358 | }, |
@@ -349,7 +363,9 @@ fn g() {} | |||
349 | label: "X", | 363 | label: "X", |
350 | navigation_range: 169..170, | 364 | navigation_range: 169..170, |
351 | node_range: 169..170, | 365 | node_range: 169..170, |
352 | kind: Variant, | 366 | kind: SymbolKind( |
367 | Variant, | ||
368 | ), | ||
353 | detail: None, | 369 | detail: None, |
354 | deprecated: false, | 370 | deprecated: false, |
355 | }, | 371 | }, |
@@ -360,7 +376,9 @@ fn g() {} | |||
360 | label: "Y", | 376 | label: "Y", |
361 | navigation_range: 172..173, | 377 | navigation_range: 172..173, |
362 | node_range: 172..178, | 378 | node_range: 172..178, |
363 | kind: Variant, | 379 | kind: SymbolKind( |
380 | Variant, | ||
381 | ), | ||
364 | detail: None, | 382 | detail: None, |
365 | deprecated: false, | 383 | deprecated: false, |
366 | }, | 384 | }, |
@@ -369,7 +387,9 @@ fn g() {} | |||
369 | label: "T", | 387 | label: "T", |
370 | navigation_range: 186..187, | 388 | navigation_range: 186..187, |
371 | node_range: 181..193, | 389 | node_range: 181..193, |
372 | kind: TypeAlias, | 390 | kind: SymbolKind( |
391 | TypeAlias, | ||
392 | ), | ||
373 | detail: Some( | 393 | detail: Some( |
374 | "()", | 394 | "()", |
375 | ), | 395 | ), |
@@ -380,7 +400,9 @@ fn g() {} | |||
380 | label: "S", | 400 | label: "S", |
381 | navigation_range: 201..202, | 401 | navigation_range: 201..202, |
382 | node_range: 194..213, | 402 | node_range: 194..213, |
383 | kind: Static, | 403 | kind: SymbolKind( |
404 | Static, | ||
405 | ), | ||
384 | detail: Some( | 406 | detail: Some( |
385 | "i32", | 407 | "i32", |
386 | ), | 408 | ), |
@@ -391,7 +413,9 @@ fn g() {} | |||
391 | label: "C", | 413 | label: "C", |
392 | navigation_range: 220..221, | 414 | navigation_range: 220..221, |
393 | node_range: 214..232, | 415 | node_range: 214..232, |
394 | kind: Const, | 416 | kind: SymbolKind( |
417 | Const, | ||
418 | ), | ||
395 | detail: Some( | 419 | detail: Some( |
396 | "i32", | 420 | "i32", |
397 | ), | 421 | ), |
@@ -402,7 +426,9 @@ fn g() {} | |||
402 | label: "impl E", | 426 | label: "impl E", |
403 | navigation_range: 239..240, | 427 | navigation_range: 239..240, |
404 | node_range: 234..243, | 428 | node_range: 234..243, |
405 | kind: Impl, | 429 | kind: SymbolKind( |
430 | Impl, | ||
431 | ), | ||
406 | detail: None, | 432 | detail: None, |
407 | deprecated: false, | 433 | deprecated: false, |
408 | }, | 434 | }, |
@@ -411,7 +437,9 @@ fn g() {} | |||
411 | label: "impl fmt::Debug for E", | 437 | label: "impl fmt::Debug for E", |
412 | navigation_range: 265..266, | 438 | navigation_range: 265..266, |
413 | node_range: 245..269, | 439 | node_range: 245..269, |
414 | kind: Impl, | 440 | kind: SymbolKind( |
441 | Impl, | ||
442 | ), | ||
415 | detail: None, | 443 | detail: None, |
416 | deprecated: false, | 444 | deprecated: false, |
417 | }, | 445 | }, |
@@ -420,7 +448,9 @@ fn g() {} | |||
420 | label: "mc", | 448 | label: "mc", |
421 | navigation_range: 284..286, | 449 | navigation_range: 284..286, |
422 | node_range: 271..303, | 450 | node_range: 271..303, |
423 | kind: Macro, | 451 | kind: SymbolKind( |
452 | Macro, | ||
453 | ), | ||
424 | detail: None, | 454 | detail: None, |
425 | deprecated: false, | 455 | deprecated: false, |
426 | }, | 456 | }, |
@@ -429,7 +459,9 @@ fn g() {} | |||
429 | label: "mcexp", | 459 | label: "mcexp", |
430 | navigation_range: 334..339, | 460 | navigation_range: 334..339, |
431 | node_range: 305..356, | 461 | node_range: 305..356, |
432 | kind: Macro, | 462 | kind: SymbolKind( |
463 | Macro, | ||
464 | ), | ||
433 | detail: None, | 465 | detail: None, |
434 | deprecated: false, | 466 | deprecated: false, |
435 | }, | 467 | }, |
@@ -438,7 +470,9 @@ fn g() {} | |||
438 | label: "mcexp", | 470 | label: "mcexp", |
439 | navigation_range: 387..392, | 471 | navigation_range: 387..392, |
440 | node_range: 358..409, | 472 | node_range: 358..409, |
441 | kind: Macro, | 473 | kind: SymbolKind( |
474 | Macro, | ||
475 | ), | ||
442 | detail: None, | 476 | detail: None, |
443 | deprecated: false, | 477 | deprecated: false, |
444 | }, | 478 | }, |
@@ -447,7 +481,9 @@ fn g() {} | |||
447 | label: "obsolete", | 481 | label: "obsolete", |
448 | navigation_range: 428..436, | 482 | navigation_range: 428..436, |
449 | node_range: 411..441, | 483 | node_range: 411..441, |
450 | kind: Function, | 484 | kind: SymbolKind( |
485 | Function, | ||
486 | ), | ||
451 | detail: Some( | 487 | detail: Some( |
452 | "fn()", | 488 | "fn()", |
453 | ), | 489 | ), |
@@ -458,7 +494,9 @@ fn g() {} | |||
458 | label: "very_obsolete", | 494 | label: "very_obsolete", |
459 | navigation_range: 481..494, | 495 | navigation_range: 481..494, |
460 | node_range: 443..499, | 496 | node_range: 443..499, |
461 | kind: Function, | 497 | kind: SymbolKind( |
498 | Function, | ||
499 | ), | ||
462 | detail: Some( | 500 | detail: Some( |
463 | "fn()", | 501 | "fn()", |
464 | ), | 502 | ), |
@@ -478,7 +516,9 @@ fn g() {} | |||
478 | label: "m", | 516 | label: "m", |
479 | navigation_range: 568..569, | 517 | navigation_range: 568..569, |
480 | node_range: 543..606, | 518 | node_range: 543..606, |
481 | kind: Module, | 519 | kind: SymbolKind( |
520 | Module, | ||
521 | ), | ||
482 | detail: None, | 522 | detail: None, |
483 | deprecated: false, | 523 | deprecated: false, |
484 | }, | 524 | }, |
@@ -500,7 +540,9 @@ fn g() {} | |||
500 | label: "f", | 540 | label: "f", |
501 | navigation_range: 575..576, | 541 | navigation_range: 575..576, |
502 | node_range: 572..581, | 542 | node_range: 572..581, |
503 | kind: Function, | 543 | kind: SymbolKind( |
544 | Function, | ||
545 | ), | ||
504 | detail: Some( | 546 | detail: Some( |
505 | "fn()", | 547 | "fn()", |
506 | ), | 548 | ), |
@@ -513,7 +555,9 @@ fn g() {} | |||
513 | label: "g", | 555 | label: "g", |
514 | navigation_range: 598..599, | 556 | navigation_range: 598..599, |
515 | node_range: 582..604, | 557 | node_range: 582..604, |
516 | kind: Function, | 558 | kind: SymbolKind( |
559 | Function, | ||
560 | ), | ||
517 | detail: Some( | 561 | detail: Some( |
518 | "fn()", | 562 | "fn()", |
519 | ), | 563 | ), |
diff --git a/crates/ide/src/syntax_highlighting/tags.rs b/crates/ide/src/syntax_highlighting/tags.rs index c7e74aed8..3c02fdb11 100644 --- a/crates/ide/src/syntax_highlighting/tags.rs +++ b/crates/ide/src/syntax_highlighting/tags.rs | |||
@@ -107,7 +107,6 @@ impl HlTag { | |||
107 | SymbolKind::ValueParam => "value_param", | 107 | SymbolKind::ValueParam => "value_param", |
108 | SymbolKind::SelfParam => "self_keyword", | 108 | SymbolKind::SelfParam => "self_keyword", |
109 | SymbolKind::Impl => "self_type", | 109 | SymbolKind::Impl => "self_type", |
110 | SymbolKind::Region => "region", | ||
111 | }, | 110 | }, |
112 | HlTag::Attribute => "attribute", | 111 | HlTag::Attribute => "attribute", |
113 | HlTag::BoolLiteral => "bool_literal", | 112 | HlTag::BoolLiteral => "bool_literal", |