diff options
author | Matthew Jasper <[email protected]> | 2020-05-10 16:08:28 +0100 |
---|---|---|
committer | Matthew Jasper <[email protected]> | 2020-05-10 16:25:51 +0100 |
commit | 11c0a5bb60f9377526a588c11c68d5471ae46aa3 (patch) | |
tree | efee8051e90104b4c10314b9588936f235c1c120 /crates/ra_ide/src | |
parent | 4578154b608fa075595103d0c933da60d55b25c8 (diff) |
Highlight mutable statics as mutable
Diffstat (limited to 'crates/ra_ide/src')
-rw-r--r-- | crates/ra_ide/src/snapshots/highlighting.html | 5 | ||||
-rw-r--r-- | crates/ra_ide/src/syntax_highlighting.rs | 8 | ||||
-rw-r--r-- | crates/ra_ide/src/syntax_highlighting/tests.rs | 7 |
3 files changed, 17 insertions, 3 deletions
diff --git a/crates/ra_ide/src/snapshots/highlighting.html b/crates/ra_ide/src/snapshots/highlighting.html index 4b12fe823..0a881d384 100644 --- a/crates/ra_ide/src/snapshots/highlighting.html +++ b/crates/ra_ide/src/snapshots/highlighting.html | |||
@@ -56,7 +56,10 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
56 | <span class="keyword">let</span> <span class="variable declaration">x</span> = <span class="numeric_literal">92</span>; | 56 | <span class="keyword">let</span> <span class="variable declaration">x</span> = <span class="numeric_literal">92</span>; |
57 | <span class="variable mutable">vec</span>.<span class="unresolved_reference">push</span>(<span class="struct">Foo</span> { <span class="field">x</span>, <span class="field">y</span>: <span class="numeric_literal">1</span> }); | 57 | <span class="variable mutable">vec</span>.<span class="unresolved_reference">push</span>(<span class="struct">Foo</span> { <span class="field">x</span>, <span class="field">y</span>: <span class="numeric_literal">1</span> }); |
58 | } | 58 | } |
59 | <span class="keyword unsafe">unsafe</span> { <span class="variable mutable">vec</span>.<span class="unresolved_reference">set_len</span>(<span class="numeric_literal">0</span>); } | 59 | <span class="keyword unsafe">unsafe</span> { |
60 | <span class="variable mutable">vec</span>.<span class="unresolved_reference">set_len</span>(<span class="numeric_literal">0</span>); | ||
61 | <span class="static mutable">STATIC_MUT</span> = <span class="numeric_literal">1</span>; | ||
62 | } | ||
60 | 63 | ||
61 | <span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable declaration mutable">x</span> = <span class="numeric_literal">42</span>; | 64 | <span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable declaration mutable">x</span> = <span class="numeric_literal">42</span>; |
62 | <span class="keyword">let</span> <span class="variable declaration mutable">y</span> = &<span class="keyword">mut</span> <span class="variable mutable">x</span>; | 65 | <span class="keyword">let</span> <span class="variable declaration mutable">y</span> = &<span class="keyword">mut</span> <span class="variable mutable">x</span>; |
diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index 6658c7bb2..9c54b92a3 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs | |||
@@ -431,10 +431,16 @@ fn highlight_name(db: &RootDatabase, def: Definition) -> Highlight { | |||
431 | hir::ModuleDef::Adt(hir::Adt::Union(_)) => HighlightTag::Union, | 431 | hir::ModuleDef::Adt(hir::Adt::Union(_)) => HighlightTag::Union, |
432 | hir::ModuleDef::EnumVariant(_) => HighlightTag::EnumVariant, | 432 | hir::ModuleDef::EnumVariant(_) => HighlightTag::EnumVariant, |
433 | hir::ModuleDef::Const(_) => HighlightTag::Constant, | 433 | hir::ModuleDef::Const(_) => HighlightTag::Constant, |
434 | hir::ModuleDef::Static(_) => HighlightTag::Static, | ||
435 | hir::ModuleDef::Trait(_) => HighlightTag::Trait, | 434 | hir::ModuleDef::Trait(_) => HighlightTag::Trait, |
436 | hir::ModuleDef::TypeAlias(_) => HighlightTag::TypeAlias, | 435 | hir::ModuleDef::TypeAlias(_) => HighlightTag::TypeAlias, |
437 | hir::ModuleDef::BuiltinType(_) => HighlightTag::BuiltinType, | 436 | hir::ModuleDef::BuiltinType(_) => HighlightTag::BuiltinType, |
437 | hir::ModuleDef::Static(s) => { | ||
438 | let mut h = Highlight::new(HighlightTag::Static); | ||
439 | if s.is_mut(db) { | ||
440 | h |= HighlightModifier::Mutable; | ||
441 | } | ||
442 | return h; | ||
443 | } | ||
438 | }, | 444 | }, |
439 | Definition::SelfType(_) => HighlightTag::SelfType, | 445 | Definition::SelfType(_) => HighlightTag::SelfType, |
440 | Definition::TypeParam(_) => HighlightTag::TypeParam, | 446 | Definition::TypeParam(_) => HighlightTag::TypeParam, |
diff --git a/crates/ra_ide/src/syntax_highlighting/tests.rs b/crates/ra_ide/src/syntax_highlighting/tests.rs index d2926ba78..13894869c 100644 --- a/crates/ra_ide/src/syntax_highlighting/tests.rs +++ b/crates/ra_ide/src/syntax_highlighting/tests.rs | |||
@@ -17,6 +17,8 @@ struct Foo { | |||
17 | pub y: i32, | 17 | pub y: i32, |
18 | } | 18 | } |
19 | 19 | ||
20 | static mut STATIC_MUT: i32 = 0; | ||
21 | |||
20 | fn foo<'a, T>() -> T { | 22 | fn foo<'a, T>() -> T { |
21 | foo::<'a, i32>() | 23 | foo::<'a, i32>() |
22 | } | 24 | } |
@@ -40,7 +42,10 @@ fn main() { | |||
40 | let x = 92; | 42 | let x = 92; |
41 | vec.push(Foo { x, y: 1 }); | 43 | vec.push(Foo { x, y: 1 }); |
42 | } | 44 | } |
43 | unsafe { vec.set_len(0); } | 45 | unsafe { |
46 | vec.set_len(0); | ||
47 | STATIC_MUT = 1; | ||
48 | } | ||
44 | 49 | ||
45 | let mut x = 42; | 50 | let mut x = 42; |
46 | let y = &mut x; | 51 | let y = &mut x; |