Skip to content

Commit

Permalink
[Rust] Fix type names in generics
Browse files Browse the repository at this point in the history
This commit ...
1. includes `all-generic-type-names` in generics
   to properly highlight all types
2. scopes static type access (e.g.: nir::) `variable.other`
   as this is the scope used everywhere else.
  • Loading branch information
deathaxe committed Feb 26, 2025
1 parent 45485e3 commit 2212957
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Rust/Rust.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,7 @@ contexts:
scope: punctuation.accessor.rust
set: [type-path-second, path-after-accessor]
- include: type-names
- include: generic-identifier-names
- include: else-pop

type-path-second:
Expand Down Expand Up @@ -813,7 +814,7 @@ contexts:
scope: punctuation.separator.rust
- match: \b(Self)\b
scope: keyword.other.rust
- match: '{{identifier}}'
- include: all-generic-type-names
- match: '(?=\S)'
pop: true
- include: types
Expand Down
8 changes: 8 additions & 0 deletions Rust/tests/syntax_test_generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ fn impl_trait_use<'a, foo>() -> impl Trait1 + use<'a, Self, foo> {}
// ^ punctuation.separator
// ^^^^ keyword.other
// ^ punctuation.separator
// ^^^ storage.type.rust
// ^ punctuation.definition.generic.end

fn impl_trait_return1<'a, 'b>() -> impl Trait<&'a u8, Ty = impl Sized + 'b> {}
Expand All @@ -501,6 +502,7 @@ fn impl_trait_return1<'a, 'b>() -> impl Trait<&'a u8, Ty = impl Sized + 'b> {}
fn impl_trait_return2() -> impl Debug + 'a {}
// ^^^^^^^^^^^^^^^^^^ meta.function meta.function.return-type
// ^^^^ storage.type.impl
// ^^^^^ storage.type.rust
// ^ keyword.operator
// ^^ storage.modifier.lifetime

Expand All @@ -526,14 +528,20 @@ fn impl_trait_with_plus() -> impl Iterator<Item = hir::GenericParam<'hir>> + Cap
// ^^^^ storage.type.impl
// ^^^^^^^^ support.type
// ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.generic - meta.generic meta.generic
// ^^^^ storage.type.rust
// ^ keyword.operator
// ^^^ variable.other.rust
// ^^ punctuation.accessor.rust
// ^^^^^^^^^^^^ storage.type.rust
// ^^^^^^ meta.generic meta.generic
// ^^^^ storage.modifier.lifetime
// ^ meta.generic - meta.generic meta.generic
// ^ keyword.operator
// ^^^^^^^^ storage.type.rust
// ^^^^ meta.generic
// ^^ storage.modifier.lifetime
// ^ keyword.operator
// ^^^^^^^^ storage.type.rust
// ^^^^ meta.generic
// ^^ storage.modifier.lifetime

0 comments on commit 2212957

Please sign in to comment.