@@ -156,7 +156,7 @@ image::https://user-images.githubusercontent.com/48062697/113020670-b7c34f00-917
156
156
// IMPORTANT: master copy of this document lives in the https://github.com/rust-analyzer/rust-analyzer repository
157
157
158
158
== Folding
159
- **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide/src/folding_ranges.rs#L30 [folding_ranges.rs]
159
+ **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide/src/folding_ranges.rs#L31 [folding_ranges.rs]
160
160
161
161
Defines folding regions for curly braced blocks, runs of consecutive import
162
162
statements, and `region` / `endregion` comment markers.
@@ -219,7 +219,7 @@ image::https://user-images.githubusercontent.com/48062697/113065566-02f85480-91b
219
219
// IMPORTANT: master copy of this document lives in the https://github.com/rust-analyzer/rust-analyzer repository
220
220
221
221
== Go to Type Definition
222
- **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide/src/goto_type_definition.rs#L6 [goto_type_definition.rs]
222
+ **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide/src/goto_type_definition.rs#L7 [goto_type_definition.rs]
223
223
224
224
Navigates to the type of an identifier.
225
225
@@ -518,13 +518,107 @@ image::https://user-images.githubusercontent.com/48062697/113065583-055aae80-91b
518
518
**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide/src/syntax_highlighting.rs#L42[syntax_highlighting.rs]
519
519
520
520
rust-analyzer highlights the code semantically.
521
- For example, `bar ` in `foo::Bar` might be colored differently depending on whether `Bar` is an enum or a trait.
522
- rust-analyzer does not specify colors directly, instead it assigns tag (like `struct`) and a set of modifiers (like `declaration`) to each token.
521
+ For example, `Bar ` in `foo::Bar` might be colored differently depending on whether `Bar` is an enum or a trait.
522
+ rust-analyzer does not specify colors directly, instead it assigns a tag (like `struct`) and a set of modifiers (like `declaration`) to each token.
523
523
It's up to the client to map those to specific colors.
524
524
525
525
The general rule is that a reference to an entity gets colored the same way as the entity itself.
526
526
We also give special modifier for `mut` and `&mut` local variables.
527
527
528
+
529
+ .Token Tags
530
+
531
+ Rust-analyzer currently emits the following token tags:
532
+
533
+ - For items:
534
+ +
535
+ [horizontal]
536
+ enum:: Emitted for enums.
537
+ function:: Emitted for free-standing functions.
538
+ macro:: Emitted for macros.
539
+ method:: Emitted for associated functions, also knowns as methods.
540
+ namespace:: Emitted for modules.
541
+ struct:: Emitted for structs.
542
+ trait:: Emitted for traits.
543
+ typeAlias:: Emitted for type aliases and `Self` in `impl`s.
544
+ union:: Emitted for unions.
545
+
546
+ - For literals:
547
+ +
548
+ [horizontal]
549
+ boolean:: Emitted for the boolean literals `true` and `false`.
550
+ character:: Emitted for character literals.
551
+ number:: Emitted for numeric literals.
552
+ string:: Emitted for string literals.
553
+ escapeSequence:: Emitted for escaped sequences inside strings like `\n`.
554
+ formatSpecifier:: Emitted for format specifiers `{:?}` in `format!`-like macros.
555
+
556
+ - For operators:
557
+ +
558
+ [horizontal]
559
+ operator:: Emitted for general operators.
560
+ arithmetic:: Emitted for the arithmetic operators `+`, `-`, `*`, `/`, `+=`, `-=`, `*=`, `/=`.
561
+ bitwise:: Emitted for the bitwise operators `|`, `&`, `!`, `^`, `|=`, `&=`, `^=`.
562
+ comparison:: Emitted for the comparison operators `>`, `<`, `==`, `>=`, `<=`, `!=`.
563
+ logical:: Emitted for the logical operators `||`, `&&`, `!`.
564
+
565
+ - For punctuation:
566
+ +
567
+ [horizontal]
568
+ punctuation:: Emitted for general punctuation.
569
+ angle:: Emitted for `<>` angle brackets.
570
+ brace:: Emitted for `{}` braces.
571
+ bracket:: Emitted for `[]` brackets.
572
+ parenthesis:: Emitted for `()` parentheses.
573
+ colon:: Emitted for the `:` token.
574
+ comma:: Emitted for the `,` token.
575
+ dot:: Emitted for the `.` token.
576
+ Semi:: Emitted for the `;` token.
577
+
578
+ //-
579
+
580
+ [horizontal]
581
+ attribute:: Emitted for attributes.
582
+ builtinType:: Emitted for builtin types like `u32`, `str` and `f32`.
583
+ comment:: Emitted for comments.
584
+ constParameter:: Emitted for const parameters.
585
+ enumMember:: Emitted for enum variants.
586
+ generic:: Emitted for generic tokens that have no mapping.
587
+ keyword:: Emitted for keywords.
588
+ label:: Emitted for labels.
589
+ lifetime:: Emitted for lifetimes.
590
+ parameter:: Emitted for non-self function parameters.
591
+ property:: Emitted for struct and union fields.
592
+ selfKeyword:: Emitted for the self function parameter and self path-specifier.
593
+ typeParameter:: Emitted for type parameters.
594
+ unresolvedReference:: Emitted for unresolved references, names that rust-analyzer can't find the definition of.
595
+ variable:: Emitted for locals, constants and statics.
596
+
597
+
598
+ .Token Modifiers
599
+
600
+ Token modifiers allow to style some elements in the source code more precisely.
601
+
602
+ Rust-analyzer currently emits the following token modifiers:
603
+
604
+ [horizontal]
605
+ async:: Emitted for async functions and the `async` and `await` keywords.
606
+ attribute:: Emitted for tokens inside attributes.
607
+ callable:: Emitted for locals whose types implements one of the `Fn*` traits.
608
+ constant:: Emitted for consts.
609
+ consuming:: Emitted for locals that are being consumed when use in a function call.
610
+ controlFlow:: Emitted for control-flow related tokens, this includes the `?` operator.
611
+ declaration:: Emitted for names of definitions, like `foo` in `fn foo() {}`.
612
+ documentation:: Emitted for documentation comments.
613
+ injected:: Emitted for doc-string injected highlighting like rust source blocks in documentation.
614
+ intraDocLink:: Emitted for intra doc links in doc-strings.
615
+ library:: Emitted for items that are defined outside of the current crate.
616
+ mutable:: Emitted for mutable locals and statics.
617
+ static:: Emitted for "static" functions, also known as functions that do not take a `self` param, as well as statics and consts.
618
+ trait:: Emitted for associated trait items.
619
+ unsafe:: Emitted for unsafe operations, like unsafe function calls, as well as the `unsafe` token.
620
+
621
+
528
622
image::https://user-images.githubusercontent.com/48062697/113164457-06cfb980-9239-11eb-819b-0f93e646acf8.png[]
529
623
image::https://user-images.githubusercontent.com/48062697/113187625-f7f50100-9250-11eb-825e-91c58f236071.png[]
530
624
0 commit comments