diff options
Diffstat (limited to 'crates/ra_ide/src/syntax_highlighting')
-rw-r--r-- | crates/ra_ide/src/syntax_highlighting/html.rs | 10 | ||||
-rw-r--r-- | crates/ra_ide/src/syntax_highlighting/tests.rs | 21 |
2 files changed, 26 insertions, 5 deletions
diff --git a/crates/ra_ide/src/syntax_highlighting/html.rs b/crates/ra_ide/src/syntax_highlighting/html.rs index 0be55bca9..a5e7d2867 100644 --- a/crates/ra_ide/src/syntax_highlighting/html.rs +++ b/crates/ra_ide/src/syntax_highlighting/html.rs | |||
@@ -1,5 +1,6 @@ | |||
1 | //! Renders a bit of code as HTML. | 1 | //! Renders a bit of code as HTML. |
2 | 2 | ||
3 | use oorandom::Rand32; | ||
3 | use ra_db::SourceDatabase; | 4 | use ra_db::SourceDatabase; |
4 | use ra_syntax::{AstNode, TextRange, TextSize}; | 5 | use ra_syntax::{AstNode, TextRange, TextSize}; |
5 | 6 | ||
@@ -9,13 +10,12 @@ pub(crate) fn highlight_as_html(db: &RootDatabase, file_id: FileId, rainbow: boo | |||
9 | let parse = db.parse(file_id); | 10 | let parse = db.parse(file_id); |
10 | 11 | ||
11 | fn rainbowify(seed: u64) -> String { | 12 | fn rainbowify(seed: u64) -> String { |
12 | use rand::prelude::*; | 13 | let mut rng = Rand32::new(seed); |
13 | let mut rng = SmallRng::seed_from_u64(seed); | ||
14 | format!( | 14 | format!( |
15 | "hsl({h},{s}%,{l}%)", | 15 | "hsl({h},{s}%,{l}%)", |
16 | h = rng.gen_range::<u16, _, _>(0, 361), | 16 | h = rng.rand_range(0..361), |
17 | s = rng.gen_range::<u16, _, _>(42, 99), | 17 | s = rng.rand_range(42..99), |
18 | l = rng.gen_range::<u16, _, _>(40, 91), | 18 | l = rng.rand_range(40..91), |
19 | ) | 19 | ) |
20 | } | 20 | } |
21 | 21 | ||
diff --git a/crates/ra_ide/src/syntax_highlighting/tests.rs b/crates/ra_ide/src/syntax_highlighting/tests.rs index 87a6e2523..730efff0d 100644 --- a/crates/ra_ide/src/syntax_highlighting/tests.rs +++ b/crates/ra_ide/src/syntax_highlighting/tests.rs | |||
@@ -9,6 +9,9 @@ use crate::{mock_analysis::single_file, FileRange, TextRange}; | |||
9 | fn test_highlighting() { | 9 | fn test_highlighting() { |
10 | check_highlighting( | 10 | check_highlighting( |
11 | r#" | 11 | r#" |
12 | use inner::{self as inner_mod}; | ||
13 | mod inner {} | ||
14 | |||
12 | #[derive(Clone, Debug)] | 15 | #[derive(Clone, Debug)] |
13 | struct Foo { | 16 | struct Foo { |
14 | pub x: i32, | 17 | pub x: i32, |
@@ -272,19 +275,37 @@ fn test_unsafe_highlighting() { | |||
272 | r#" | 275 | r#" |
273 | unsafe fn unsafe_fn() {} | 276 | unsafe fn unsafe_fn() {} |
274 | 277 | ||
278 | union Union { | ||
279 | a: u32, | ||
280 | b: f32, | ||
281 | } | ||
282 | |||
275 | struct HasUnsafeFn; | 283 | struct HasUnsafeFn; |
276 | 284 | ||
277 | impl HasUnsafeFn { | 285 | impl HasUnsafeFn { |
278 | unsafe fn unsafe_method(&self) {} | 286 | unsafe fn unsafe_method(&self) {} |
279 | } | 287 | } |
280 | 288 | ||
289 | struct TypeForStaticMut { | ||
290 | a: u8 | ||
291 | } | ||
292 | |||
293 | static mut global_mut: TypeForStaticMut = TypeForStaticMut { a: 0 }; | ||
294 | |||
281 | fn main() { | 295 | fn main() { |
282 | let x = &5 as *const usize; | 296 | let x = &5 as *const usize; |
297 | let u = Union { b: 0 }; | ||
283 | unsafe { | 298 | unsafe { |
284 | unsafe_fn(); | 299 | unsafe_fn(); |
300 | let b = u.b; | ||
301 | match u { | ||
302 | Union { b: 0 } => (), | ||
303 | Union { a } => (), | ||
304 | } | ||
285 | HasUnsafeFn.unsafe_method(); | 305 | HasUnsafeFn.unsafe_method(); |
286 | let y = *(x); | 306 | let y = *(x); |
287 | let z = -x; | 307 | let z = -x; |
308 | let a = global_mut.a; | ||
288 | } | 309 | } |
289 | } | 310 | } |
290 | "# | 311 | "# |