From 11c0a5bb60f9377526a588c11c68d5471ae46aa3 Mon Sep 17 00:00:00 2001 From: Matthew Jasper Date: Sun, 10 May 2020 16:08:28 +0100 Subject: Highlight mutable statics as mutable --- crates/ra_ide/src/snapshots/highlighting.html | 5 ++++- crates/ra_ide/src/syntax_highlighting.rs | 8 +++++++- crates/ra_ide/src/syntax_highlighting/tests.rs | 7 ++++++- 3 files changed, 17 insertions(+), 3 deletions(-) (limited to 'crates/ra_ide') 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 let x = 92; vec.push(Foo { x, y: 1 }); } - unsafe { vec.set_len(0); } + unsafe { + vec.set_len(0); + STATIC_MUT = 1; + } let mut x = 42; let y = &mut x; 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 { hir::ModuleDef::Adt(hir::Adt::Union(_)) => HighlightTag::Union, hir::ModuleDef::EnumVariant(_) => HighlightTag::EnumVariant, hir::ModuleDef::Const(_) => HighlightTag::Constant, - hir::ModuleDef::Static(_) => HighlightTag::Static, hir::ModuleDef::Trait(_) => HighlightTag::Trait, hir::ModuleDef::TypeAlias(_) => HighlightTag::TypeAlias, hir::ModuleDef::BuiltinType(_) => HighlightTag::BuiltinType, + hir::ModuleDef::Static(s) => { + let mut h = Highlight::new(HighlightTag::Static); + if s.is_mut(db) { + h |= HighlightModifier::Mutable; + } + return h; + } }, Definition::SelfType(_) => HighlightTag::SelfType, 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 { pub y: i32, } +static mut STATIC_MUT: i32 = 0; + fn foo<'a, T>() -> T { foo::<'a, i32>() } @@ -40,7 +42,10 @@ fn main() { let x = 92; vec.push(Foo { x, y: 1 }); } - unsafe { vec.set_len(0); } + unsafe { + vec.set_len(0); + STATIC_MUT = 1; + } let mut x = 42; let y = &mut x; -- cgit v1.2.3 From 22b75c4ceaefbaf26e63540b3e2d6705375c043c Mon Sep 17 00:00:00 2001 From: Matthew Jasper Date: Sun, 10 May 2020 16:08:54 +0100 Subject: Highlight the name in macro declarations --- crates/ra_ide/src/snapshots/highlight_strings.html | 4 ++-- crates/ra_ide/src/snapshots/highlighting.html | 4 +++- crates/ra_ide/src/syntax_highlighting.rs | 13 +++++++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/snapshots/highlight_strings.html b/crates/ra_ide/src/snapshots/highlight_strings.html index de06daf72..752b487e8 100644 --- a/crates/ra_ide/src/snapshots/highlight_strings.html +++ b/crates/ra_ide/src/snapshots/highlight_strings.html @@ -27,13 +27,13 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .keyword.unsafe { color: #BC8383; font-weight: bold; } .control { font-style: italic; } -
macro_rules! println {
+
macro_rules! println {
     ($($arg:tt)*) => ({
         $crate::io::_print($crate::format_args_nl!($($arg)*));
     })
 }
 #[rustc_builtin_macro]
-macro_rules! format_args_nl {
+macro_rules! format_args_nl {
     ($fmt:expr) => {{ /* compiler built-in */ }};
     ($fmt:expr, $($args:tt)*) => {{ /* compiler built-in */ }};
 }
diff --git a/crates/ra_ide/src/snapshots/highlighting.html b/crates/ra_ide/src/snapshots/highlighting.html
index 0a881d384..4c27aade4 100644
--- a/crates/ra_ide/src/snapshots/highlighting.html
+++ b/crates/ra_ide/src/snapshots/highlighting.html
@@ -33,11 +33,13 @@ pre                 { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
     pub y: i32,
 }
 
+static mut STATIC_MUT: i32 = 0;
+
 fn foo<'a, T>() -> T {
     foo::<'a, i32>()
 }
 
-macro_rules! def_fn {
+macro_rules! def_fn {
     ($($tt:tt)*) => {$($tt)*}
 }
 
diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs
index 9c54b92a3..d53a39f57 100644
--- a/crates/ra_ide/src/syntax_highlighting.rs
+++ b/crates/ra_ide/src/syntax_highlighting.rs
@@ -167,6 +167,19 @@ pub(crate) fn highlight(
                         binding_hash: None,
                     });
                 }
+                if let Some(name) = mc.is_macro_rules() {
+                    if let Some((highlight, binding_hash)) = highlight_element(
+                        &sema,
+                        &mut bindings_shadow_count,
+                        name.syntax().clone().into(),
+                    ) {
+                        stack.add(HighlightedRange {
+                            range: name.syntax().text_range(),
+                            highlight,
+                            binding_hash,
+                        });
+                    }
+                }
                 continue;
             }
             WalkEvent::Leave(Some(mc)) => {
-- 
cgit v1.2.3