Skip to content

Commit

Permalink
[Rust] scope support types in generics (sublimehq#1820)
Browse files Browse the repository at this point in the history
  • Loading branch information
keith-hall authored and wbond committed Jan 7, 2019
1 parent 4769288 commit 2c2772b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
9 changes: 7 additions & 2 deletions Rust/Rust.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ variables:
escaped_byte: '\\(x\h{2}|n|r|t|0|"|''|\\)'
escaped_char: '\\(x\h{2}|n|r|t|0|"|''|\\|u\{\h{1,6}\})'
int_suffixes: 'i8|i16|i32|i64|isize|u8|u16|u32|u64|usize'
support_type: \b(Copy|Send|Sized|Sync|Drop|Fn|FnMut|FnOnce|Box|ToOwned|Clone|PartialEq|PartialOrd|Eq|Ord|AsRef|AsMut|Into|From|Default|Iterator|Extend|IntoIterator|DoubleEndedIterator|ExactSizeIterator|Option|Some|None|Result|Ok|Err|SliceConcatExt|String|ToString|Vec)\b
contexts:
main:
- include: statements
Expand Down Expand Up @@ -188,7 +189,7 @@ contexts:
- match: '\b[[:lower:]_][[:lower:][:digit:]_]*!(?=\s*(\(|\{|\[))'
scope: support.macro.rust

- match: \b(Copy|Send|Sized|Sync|Drop|Fn|FnMut|FnOnce|Box|ToOwned|Clone|PartialEq|PartialOrd|Eq|Ord|AsRef|AsMut|Into|From|Default|Iterator|Extend|IntoIterator|DoubleEndedIterator|ExactSizeIterator|Option|Some|None|Result|Ok|Err|SliceConcatExt|String|ToString|Vec)\b
- match: '{{support_type}}'
scope: support.type.rust

- include: basic-identifiers
Expand Down Expand Up @@ -427,7 +428,9 @@ contexts:
- include: block

type:
- match: '{{identifier}}(?=<)'
- match: (?:{{support_type}}|{{identifier}})(?=<)
captures:
1: support.type.rust
push: generic-angles
- match: \b(Self|i8|i16|i32|i64|isize|u8|u16|u32|u64|usize|f32|f64|bool|char|str)\b
scope: storage.type.rust
Expand Down Expand Up @@ -484,6 +487,8 @@ contexts:
pop: true
- include: generic-angles-contents
- include: type-any-identifier
- match: '{{support_type}}'
scope: support.type.rust
- match: ':'
scope: punctuation.separator.rust
- match: '\+'
Expand Down
5 changes: 5 additions & 0 deletions Rust/syntax_test_rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ struct PrintableStruct(Box<i32>);
//^^^^ storage.type.struct
// ^^^^^^^^^^^^^^^ entity.name.struct
// ^ punctuation.section.group.begin
// ^^^ support.type
// ^^^^^^^^ meta.generic
// ^ punctuation.definition.generic.begin
// ^^^ storage.type
Expand Down Expand Up @@ -808,6 +809,7 @@ pub trait Animal {

fn collect_vec() {
let _: Vec<(usize, usize)> = (0..10).enumerate().collect::<Vec<_>>();
// ^^^ support.type
// ^^^^^^^^^^^^^^^^^^^ meta.generic
// ^ punctuation.section.group.begin
// ^^^^^ storage.type
Expand All @@ -825,6 +827,7 @@ fn collect_vec() {
// ^ punctuation.accessor.dot
// ^^ punctuation.accessor
// ^^^^^^^^ meta.generic
// ^^^ support.type
// ^^^^^^ meta.generic meta.generic
// ^ keyword.operator
let _: Vec<(usize, usize)> = vec!();
Expand All @@ -833,6 +836,8 @@ fn collect_vec() {
// ^^^^ support.macro
let _: Vec<(usize, usize)> = vec![];
// ^^^^ support.macro
let _: Vec<String> = vec![];
// ^^^^^^ meta.generic support.type
}

macro_rules! forward_ref_binop [
Expand Down

0 comments on commit 2c2772b

Please sign in to comment.