Skip to content

Syntax: Fix raw pointers, and index const and static symbols (for Goto-Symbol). #335

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions RustEnhanced.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,19 @@ contexts:
scope: storage.type.enum.rust
push: enum-identifier

- include: raw-pointer

- match: '\b(const)\s+({{identifier}})'
captures:
1: storage.type.rust
2: entity.name.constant.rust

- match: '\b(static)\s+(?:(mut)\s+)?({{identifier}})'
captures:
1: storage.type.rust
2: storage.modifier.rust
3: entity.name.constant.rust

- match: '\b(break|continue)(?:\s+(''{{identifier}}))?'
captures:
1: keyword.control.rust
Expand Down Expand Up @@ -412,6 +425,7 @@ contexts:
- include: return-type
- match: '&'
scope: keyword.operator.rust
- include: raw-pointer
- match: \b(mut|ref|const|unsafe)\b
scope: storage.modifier.rust
- match: \b(fn)\b(\()
Expand Down Expand Up @@ -459,6 +473,10 @@ contexts:
- match: '!'
scope: keyword.operator.rust

raw-pointer:
- match: '\*\s*(?:const|mut)\b'
scope: storage.modifier.rust

hrtb:
- match: \bfor\b
scope: keyword.other.rust
Expand Down
2 changes: 1 addition & 1 deletion RustSymbols.JSON-tmPreferences
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Rust Symbols",
"scope": "entity.name.function.rust, entity.name.macro.rust, entity.name.struct.rust, entity.name.enum.rust, entity.name.module.rust, entity.name.type.rust, entity.name.trait.rust",
"scope": "entity.name.function.rust, entity.name.macro.rust, entity.name.struct.rust, entity.name.enum.rust, entity.name.module.rust, entity.name.type.rust, entity.name.trait.rust, entity.name.constant.rust",
"settings": {
"showInSymbolList": 1,
"showInIndexedSymbolList": 1
Expand Down
2 changes: 1 addition & 1 deletion RustSymbols.tmPreferences
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<key>name</key>
<string>Rust Symbols</string>
<key>scope</key>
<string>entity.name.function.rust, entity.name.macro.rust, entity.name.struct.rust, entity.name.enum.rust, entity.name.module.rust, entity.name.type.rust, entity.name.trait.rust</string>
<string>entity.name.function.rust, entity.name.macro.rust, entity.name.struct.rust, entity.name.enum.rust, entity.name.module.rust, entity.name.type.rust, entity.name.trait.rust, entity.name.constant.rust</string>
<key>settings</key>
<dict>
<key>showInIndexedSymbolList</key>
Expand Down
30 changes: 23 additions & 7 deletions tests/syntax-rust/syntax_test_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,23 @@ type GenFnPointer2 = Bar<extern "C" fn()>;

const ZERO: u64 = 0;
// <- storage.type
// ^^^^ constant.other
// ^^^^ entity.name.constant
// ^ punctuation.separator
// ^^^ storage.type
// ^ keyword.operator
// ^ constant.numeric.integer.decimal
static NAME: &'static str = "John";
// <- storage.type
// ^^^^ entity.name.constant
// ^ keyword.operator
// ^^^^^^^ storage.modifier.lifetime
// ^^^ storage.type
// ^ keyword.operator
// ^^^^^^ string.quoted.double

static mut BRAVO: u32 = 0;
// <- storage.type
// ^^^ storage.modifier
// ^^^^^ entity.name.constant

// Function type in a box return type.
// fixes https://github.com/rust-lang/sublime-rust/issues/144
Expand Down Expand Up @@ -121,13 +125,25 @@ let slice: &[i32];


// Pointer types.
let p: *const T;
// ^ keyword.operator
// ^^^^^ storage.type
let p: *const Foo;
// ^^^^^^ storage.modifier
// ^^^ storage.type.source
let p: *mut u8;
// ^ keyword.operator
// ^^^ storage.modifier
// ^^^^ storage.modifier
// ^^ storage.type
let raw = &x as *const i32;
// ^^^^^^ storage.modifier
// ^^^ storage.type
let raw_mut = &mut y as *mut i32;
// ^^^^ storage.modifier
// ^^^ storage.type
let p_imm: *const u32 = &i as *const u32;
// ^^^^^^ storage.modifier
// ^^^^^^ storage.modifier
// ^^^ storage.type
type ExampleRawPointer = HashMap<*const i32, Option<i32>, BuildHasherDefault<FnvHasher>>;
// ^^^^^^ meta.generic storage.modifier
// ^^^ meta.generic storage.type


// Anonymous lifetimes.
Expand Down