diff --git a/RustEnhanced.sublime-syntax b/RustEnhanced.sublime-syntax index dc2a14dd..025746ae 100644 --- a/RustEnhanced.sublime-syntax +++ b/RustEnhanced.sublime-syntax @@ -25,6 +25,8 @@ contexts: statements: + - include: visibility + - match: ';' scope: punctuation.terminator.rust @@ -36,11 +38,10 @@ contexts: - match: '''{{identifier}}(?!\'')\b' scope: storage.modifier.lifetime.rust - - match: '\b(?:(pub)\s+)?\b(mod)\s+({{identifier}})\b' + - match: '\b(mod)\s+({{identifier}})\b' captures: - 1: storage.modifier.rust - 2: storage.type.module.rust - 3: entity.name.module.rust + 1: storage.type.module.rust + 2: entity.name.module.rust push: - meta_scope: meta.module.rust - match: ';' @@ -53,32 +54,23 @@ contexts: 2: keyword.operator.rust push: closure - - match: '\b(?:(pub)\s+)?\b(fn)\s+(?={{identifier}})' - scope: meta.function.rust + - match: '\b(fn)\s+(?={{identifier}})' captures: - 1: storage.modifier.rust - 2: storage.type.function.rust + 1: storage.type.function.rust push: fn-definition - - match: '\b(?:(pub)\s+)?(struct)\s+' - scope: meta.struct.rust - captures: - 1: storage.modifier.rust - 2: storage.type.struct.rust + - match: '\bstruct\b' + scope: storage.type.struct.rust push: struct-identifier - - match: '\b(?:(pub)\s+)?(union)\s+' - scope: meta.union.rust - captures: - 1: storage.modifier.rust - 2: storage.type.union.rust + - match: '\bunion\b' + scope: storage.type.union.rust push: union-identifier - - match: '\b(?:(pub)\s+)?(type)\s+({{identifier}})\b' + - match: '\b(type)\s+({{identifier}})\b' captures: - 1: storage.modifier.rust - 2: storage.type.type.rust - 3: entity.name.type.rust + 1: storage.type.type.rust + 2: entity.name.type.rust push: - match: '=(?!=)' scope: keyword.operator.rust @@ -86,11 +78,10 @@ contexts: - match: '(?=\S)' pop: true - - match: '\b(?:(pub)\s+)?(trait)\s+({{identifier}})\b' + - match: '\b(trait)\s+({{identifier}})\b' captures: - 1: storage.modifier.rust - 2: storage.type.trait.rust - 3: entity.name.trait.rust + 1: storage.type.trait.rust + 2: entity.name.trait.rust push: - meta_scope: meta.trait.rust - include: statements-block @@ -99,11 +90,10 @@ contexts: scope: storage.type.impl.rust push: impl-definition - - match: '\b(?:(pub)\s+)?(enum)\s+({{identifier}})\b' + - match: '\b(enum)\s+({{identifier}})\b' captures: - 1: storage.modifier.rust - 2: storage.type.enum.rust - 3: entity.name.enum.rust + 1: storage.type.enum.rust + 2: entity.name.enum.rust push: - meta_scope: meta.enum.rust - include: statements-block @@ -265,6 +255,25 @@ contexts: - match: '[-=<>&|!~@?+*/%^''#$]' scope: keyword.operator.rust + visibility: + - match: '\b(pub)\s*(\()' + captures: + 1: storage.modifier.rust + 2: punctuation.definition.group.begin.rust + push: + - include: comments + - match: '\)' + scope: punctuation.definition.group.end.rust + pop: true + - match: '(crate|in|self|super)' + scope: keyword.other.rust + - match: '::' + scope: meta.path.rust + - match: '{{identifier}}' + scope: meta.path.rust + - match: '\bpub\b' + scope: storage.modifier.rust + attribute: - match: '#!?\[' push: @@ -511,6 +520,7 @@ contexts: scope: keyword.operator.rust struct-identifier: + - meta_scope: meta.struct.rust - match: '{{identifier}}(?=<)' scope: entity.name.struct.rust set: @@ -542,14 +552,12 @@ contexts: pop: true - match: '\(' scope: punctuation.definition.group.begin.rust - # Ensure that we end the tuple at the next ) to - # prevent odd highlighting as the user is typing - with_prototype: + push: - match: '(?=\))' pop: true - push: - meta_scope: meta.group.rust - include: comments + - include: visibility - include: type-any-identifier struct-classic: @@ -567,8 +575,7 @@ contexts: pop: true - include: comments - include: attribute - - match: \bpub\b - scope: storage.modifier.rust + - include: visibility - match: '{{identifier}}(?=\s*:)' scope: variable.other.member.rust push: @@ -581,6 +588,7 @@ contexts: union-identifier: + - meta_scope: meta.union.rust - match: '{{identifier}}(?=<)' scope: entity.name.union.rust set: diff --git a/syntax_test_rust.rs b/syntax_test_rust.rs index 6164ba7f..914e0165 100644 --- a/syntax_test_rust.rs +++ b/syntax_test_rust.rs @@ -32,7 +32,7 @@ extern extern crate simd_rng_derive;*/ // This one is just to visually confirm the testing comments don't intefere #[macro_use] extern crate std_web; -/*#[macro_use] +/*#[macro_use] extern extern crate simd_rng_derive;*/ let c = 'c'; @@ -755,7 +755,7 @@ fn my_other_func(e: OperatingSystem) -> u32 { // Test highlighting/scope with struct field attributes // https://github.com/rust-lang/sublime-rust/issues/120 pub struct Claim { -// ^^^^^^^^^ meta.struct +// ^^^^^^^^ meta.struct pub claim_id: String, // ^^^ storage.modifier.rust pub patient_id: String, @@ -888,7 +888,7 @@ pub fn from_buf_reader(s: io::BufReader) -> Result } pub mod my_mod { -//^^^^^^^^^^^^^^ meta.module +// ^^^^^^^^^^^^ meta.module // <- storage.modifier // ^^^ storage.type.module // ^^^^^^ entity.name.module @@ -953,7 +953,7 @@ impl<'a, T: MyTrait + OtherTrait> PrintInOption for T where pub trait Animal { // <- storage.modifier -//^^^^^^^^^^^^^^^^ meta.trait +// ^^^^^^^^^^^^^^ meta.trait // ^ meta.block punctuation.definition.block.begin fn noise(quiet: bool) { // Comment @@ -1265,7 +1265,7 @@ struct A(T) where T: AsRef; // ^ punctuation.terminator // ^^^^^ meta.struct meta.where keyword.other pub struct A(T) -//^^^^^^^^^^^^ meta.struct +// ^^^^^^^^^^ meta.struct // ^^^^^^ meta.struct storage.type where //^^^ meta.struct meta.where keyword.other @@ -1323,7 +1323,7 @@ union Union { pub union Foo<'a, Y: Baz> // <- storage.modifier -//^^^^^^^^^^^^^^^^^^^^^^^ meta.union +// ^^^^^^^^^^^^^^^^^^^^^ meta.union // ^^^^^ meta.union storage.type.union // ^^^ meta.union meta.generic entity.name.union // ^ meta.union meta.generic meta.generic punctuation.definition.generic.begin @@ -1352,3 +1352,86 @@ impl Thing for &'a mut A {} // ^^ meta.impl storage.modifier.lifetime // ^^^ meta.impl storage.modifier // ^ meta.impl entity.name.impl + +pub ( crate ) struct S {} +// <- storage.modifier +// ^ punctuation.definition.group.begin +// ^^^^^ keyword.other +// ^ punctuation.definition.group.end +// ^^^^^^^^^^^ meta.struct +pub ( in foo::bar ) union U {} +// ^ punctuation.definition.group.begin +// ^^ keyword.other +// ^^^^^^^^ meta.path +// ^ punctuation.definition.group.end +// ^^^^^^^^^^ meta.union +pub ( in foo :: bar ) type T = i32; +// ^ punctuation.definition.group.begin +// ^^ keyword.other +// ^^^ meta.path +// ^^ meta.path +// ^^^ meta.path +// ^ punctuation.definition.group.end +// ^^^^ storage.type.type +pub ( in ::foo ) fn f() {} +// ^^^^^ meta.path +// ^^^^^^^^^ meta.function +pub ( self ) mod m {} +// ^^^^ keyword.other +// ^^^^^^^^ meta.module +pub ( super ) use a::b; +// ^^^^^ keyword.other +// ^^^ keyword.other +pub ( in self ) enum E {A,B} +// ^^ keyword.other +// ^^^^ keyword.other +// ^^^^^^^^^^^^ meta.enum +pub ( in super ) const CONST: i32 = 1; +// ^^ keyword.other +// ^^^^^ keyword.other +// ^^^^^ storage.type +pub ( in super::super ) static STATIC: i32 = 1; +// ^^ keyword.other +// ^^^^^ keyword.other +// ^^ meta.path +// ^^^^^ keyword.other +// ^^^^^^ storage.type + +struct S { + pub f1: i32, +// ^^^ meta.struct storage.modifier +// ^^ meta.struct variable.other.member + pub(crate) f2: i32, +// ^^^ meta.struct storage.modifier +// ^ meta.struct punctuation.definition.group.begin +// ^^^^^ meta.struct keyword.other +// ^ meta.struct punctuation.definition.group.end +// ^^ meta.struct variable.other.member + pub(in super::foo) f3: i32, +// ^^^ meta.struct storage.modifier +// ^ meta.struct punctuation.definition.group.begin +// ^^ meta.struct keyword.other +// ^^^^^ meta.struct keyword.other +// ^^^^^ meta.struct meta.path +// ^ meta.struct punctuation.definition.group.end +// ^^ meta.struct variable.other.member +} + +struct S ( + pub i32, +// ^^^ meta.struct storage.modifier +// ^^^ meta.struct storage.type + pub(crate) i32, +// ^^^ meta.struct storage.modifier +// ^ meta.struct punctuation.definition.group.begin +// ^^^^^ meta.struct keyword.other +// ^ meta.struct punctuation.definition.group.end +// ^^^ meta.struct storage.type + pub(in super) i32, +// ^^^ meta.struct storage.modifier +// ^ meta.struct punctuation.definition.group.begin +// ^^ meta.struct keyword.other +// ^^^^^ meta.struct keyword.other +// ^ meta.struct punctuation.definition.group.end +// ^^^ meta.struct storage.type +);