diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_ide/Cargo.toml | 2 | ||||
-rw-r--r-- | crates/ra_ide/src/syntax_highlighting/html.rs | 10 | ||||
-rw-r--r-- | crates/ra_ide/test_data/rainbow_highlighting.html | 12 | ||||
-rw-r--r-- | crates/rust-analyzer/Cargo.toml | 2 | ||||
-rw-r--r-- | crates/rust-analyzer/src/cli/analysis_stats.rs | 25 |
5 files changed, 33 insertions, 18 deletions
diff --git a/crates/ra_ide/Cargo.toml b/crates/ra_ide/Cargo.toml index 6f8107491..f4181c4eb 100644 --- a/crates/ra_ide/Cargo.toml +++ b/crates/ra_ide/Cargo.toml | |||
@@ -17,7 +17,7 @@ indexmap = "1.3.2" | |||
17 | itertools = "0.9.0" | 17 | itertools = "0.9.0" |
18 | log = "0.4.8" | 18 | log = "0.4.8" |
19 | rustc-hash = "1.1.0" | 19 | rustc-hash = "1.1.0" |
20 | rand = { version = "0.7.3", features = ["small_rng"] } | 20 | oorandom = "11.1.2" |
21 | 21 | ||
22 | stdx = { path = "../stdx" } | 22 | stdx = { path = "../stdx" } |
23 | 23 | ||
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/test_data/rainbow_highlighting.html b/crates/ra_ide/test_data/rainbow_highlighting.html index 08d83302c..401e87a73 100644 --- a/crates/ra_ide/test_data/rainbow_highlighting.html +++ b/crates/ra_ide/test_data/rainbow_highlighting.html | |||
@@ -36,14 +36,14 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
36 | .unresolved_reference { color: #FC5555; text-decoration: wavy underline; } | 36 | .unresolved_reference { color: #FC5555; text-decoration: wavy underline; } |
37 | </style> | 37 | </style> |
38 | <pre><code><span class="keyword">fn</span> <span class="function declaration">main</span><span class="punctuation">(</span><span class="punctuation">)</span> <span class="punctuation">{</span> | 38 | <pre><code><span class="keyword">fn</span> <span class="function declaration">main</span><span class="punctuation">(</span><span class="punctuation">)</span> <span class="punctuation">{</span> |
39 | <span class="keyword">let</span> <span class="variable declaration" data-binding-hash="8121853618659664005" style="color: hsl(261,57%,61%);">hello</span> <span class="operator">=</span> <span class="string_literal">"hello"</span><span class="punctuation">;</span> | 39 | <span class="keyword">let</span> <span class="variable declaration" data-binding-hash="8121853618659664005" style="color: hsl(273,88%,88%);">hello</span> <span class="operator">=</span> <span class="string_literal">"hello"</span><span class="punctuation">;</span> |
40 | <span class="keyword">let</span> <span class="variable declaration" data-binding-hash="2705725358298919760" style="color: hsl(17,51%,74%);">x</span> <span class="operator">=</span> <span class="variable" data-binding-hash="8121853618659664005" style="color: hsl(261,57%,61%);">hello</span><span class="punctuation">.</span><span class="unresolved_reference">to_string</span><span class="punctuation">(</span><span class="punctuation">)</span><span class="punctuation">;</span> | 40 | <span class="keyword">let</span> <span class="variable declaration" data-binding-hash="2705725358298919760" style="color: hsl(76,47%,83%);">x</span> <span class="operator">=</span> <span class="variable" data-binding-hash="8121853618659664005" style="color: hsl(273,88%,88%);">hello</span><span class="punctuation">.</span><span class="unresolved_reference">to_string</span><span class="punctuation">(</span><span class="punctuation">)</span><span class="punctuation">;</span> |
41 | <span class="keyword">let</span> <span class="variable declaration" data-binding-hash="3365759661443752373" style="color: hsl(127,76%,66%);">y</span> <span class="operator">=</span> <span class="variable" data-binding-hash="8121853618659664005" style="color: hsl(261,57%,61%);">hello</span><span class="punctuation">.</span><span class="unresolved_reference">to_string</span><span class="punctuation">(</span><span class="punctuation">)</span><span class="punctuation">;</span> | 41 | <span class="keyword">let</span> <span class="variable declaration" data-binding-hash="3365759661443752373" style="color: hsl(15,86%,51%);">y</span> <span class="operator">=</span> <span class="variable" data-binding-hash="8121853618659664005" style="color: hsl(273,88%,88%);">hello</span><span class="punctuation">.</span><span class="unresolved_reference">to_string</span><span class="punctuation">(</span><span class="punctuation">)</span><span class="punctuation">;</span> |
42 | 42 | ||
43 | <span class="keyword">let</span> <span class="variable declaration" data-binding-hash="794745962933817518" style="color: hsl(19,74%,76%);">x</span> <span class="operator">=</span> <span class="string_literal">"other color please!"</span><span class="punctuation">;</span> | 43 | <span class="keyword">let</span> <span class="variable declaration" data-binding-hash="794745962933817518" style="color: hsl(127,71%,87%);">x</span> <span class="operator">=</span> <span class="string_literal">"other color please!"</span><span class="punctuation">;</span> |
44 | <span class="keyword">let</span> <span class="variable declaration" data-binding-hash="6717528807933952652" style="color: hsl(85,49%,84%);">y</span> <span class="operator">=</span> <span class="variable" data-binding-hash="794745962933817518" style="color: hsl(19,74%,76%);">x</span><span class="punctuation">.</span><span class="unresolved_reference">to_string</span><span class="punctuation">(</span><span class="punctuation">)</span><span class="punctuation">;</span> | 44 | <span class="keyword">let</span> <span class="variable declaration" data-binding-hash="6717528807933952652" style="color: hsl(90,74%,79%);">y</span> <span class="operator">=</span> <span class="variable" data-binding-hash="794745962933817518" style="color: hsl(127,71%,87%);">x</span><span class="punctuation">.</span><span class="unresolved_reference">to_string</span><span class="punctuation">(</span><span class="punctuation">)</span><span class="punctuation">;</span> |
45 | <span class="punctuation">}</span> | 45 | <span class="punctuation">}</span> |
46 | 46 | ||
47 | <span class="keyword">fn</span> <span class="function declaration">bar</span><span class="punctuation">(</span><span class="punctuation">)</span> <span class="punctuation">{</span> | 47 | <span class="keyword">fn</span> <span class="function declaration">bar</span><span class="punctuation">(</span><span class="punctuation">)</span> <span class="punctuation">{</span> |
48 | <span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable declaration mutable" data-binding-hash="8121853618659664005" style="color: hsl(261,57%,61%);">hello</span> <span class="operator">=</span> <span class="string_literal">"hello"</span><span class="punctuation">;</span> | 48 | <span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable declaration mutable" data-binding-hash="8121853618659664005" style="color: hsl(273,88%,88%);">hello</span> <span class="operator">=</span> <span class="string_literal">"hello"</span><span class="punctuation">;</span> |
49 | <span class="punctuation">}</span></code></pre> \ No newline at end of file | 49 | <span class="punctuation">}</span></code></pre> \ No newline at end of file |
diff --git a/crates/rust-analyzer/Cargo.toml b/crates/rust-analyzer/Cargo.toml index 3f9c820c5..931fc61ed 100644 --- a/crates/rust-analyzer/Cargo.toml +++ b/crates/rust-analyzer/Cargo.toml | |||
@@ -23,7 +23,7 @@ log = "0.4.8" | |||
23 | lsp-types = { version = "0.78.0", features = ["proposed"] } | 23 | lsp-types = { version = "0.78.0", features = ["proposed"] } |
24 | parking_lot = "0.11.0" | 24 | parking_lot = "0.11.0" |
25 | pico-args = "0.3.1" | 25 | pico-args = "0.3.1" |
26 | rand = { version = "0.7.3", features = ["small_rng"] } | 26 | oorandom = "11.1.2" |
27 | rustc-hash = "1.1.0" | 27 | rustc-hash = "1.1.0" |
28 | serde = { version = "1.0.106", features = ["derive"] } | 28 | serde = { version = "1.0.106", features = ["derive"] } |
29 | serde_json = "1.0.48" | 29 | serde_json = "1.0.48" |
diff --git a/crates/rust-analyzer/src/cli/analysis_stats.rs b/crates/rust-analyzer/src/cli/analysis_stats.rs index ccc058682..6b7c08971 100644 --- a/crates/rust-analyzer/src/cli/analysis_stats.rs +++ b/crates/rust-analyzer/src/cli/analysis_stats.rs | |||
@@ -1,7 +1,10 @@ | |||
1 | //! Fully type-check project and print various stats, like the number of type | 1 | //! Fully type-check project and print various stats, like the number of type |
2 | //! errors. | 2 | //! errors. |
3 | 3 | ||
4 | use std::{path::Path, time::Instant}; | 4 | use std::{ |
5 | path::Path, | ||
6 | time::{Instant, SystemTime, UNIX_EPOCH}, | ||
7 | }; | ||
5 | 8 | ||
6 | use hir::{ | 9 | use hir::{ |
7 | db::{AstDatabase, DefDatabase, HirDatabase}, | 10 | db::{AstDatabase, DefDatabase, HirDatabase}, |
@@ -10,12 +13,12 @@ use hir::{ | |||
10 | use hir_def::FunctionId; | 13 | use hir_def::FunctionId; |
11 | use hir_ty::{Ty, TypeWalk}; | 14 | use hir_ty::{Ty, TypeWalk}; |
12 | use itertools::Itertools; | 15 | use itertools::Itertools; |
16 | use oorandom::Rand32; | ||
13 | use ra_db::{ | 17 | use ra_db::{ |
14 | salsa::{self, ParallelDatabase}, | 18 | salsa::{self, ParallelDatabase}, |
15 | SourceDatabaseExt, | 19 | SourceDatabaseExt, |
16 | }; | 20 | }; |
17 | use ra_syntax::AstNode; | 21 | use ra_syntax::AstNode; |
18 | use rand::{seq::SliceRandom, thread_rng}; | ||
19 | use rayon::prelude::*; | 22 | use rayon::prelude::*; |
20 | use rustc_hash::FxHashSet; | 23 | use rustc_hash::FxHashSet; |
21 | use stdx::format_to; | 24 | use stdx::format_to; |
@@ -46,6 +49,11 @@ pub fn analysis_stats( | |||
46 | load_output_dirs: bool, | 49 | load_output_dirs: bool, |
47 | with_proc_macro: bool, | 50 | with_proc_macro: bool, |
48 | ) -> Result<()> { | 51 | ) -> Result<()> { |
52 | let mut rng = { | ||
53 | let seed = SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_millis() as u64; | ||
54 | Rand32::new(seed) | ||
55 | }; | ||
56 | |||
49 | let db_load_time = Instant::now(); | 57 | let db_load_time = Instant::now(); |
50 | let (host, vfs) = load_cargo(path, load_output_dirs, with_proc_macro)?; | 58 | let (host, vfs) = load_cargo(path, load_output_dirs, with_proc_macro)?; |
51 | let db = host.raw_database(); | 59 | let db = host.raw_database(); |
@@ -57,7 +65,7 @@ pub fn analysis_stats( | |||
57 | 65 | ||
58 | let mut krates = Crate::all(db); | 66 | let mut krates = Crate::all(db); |
59 | if randomize { | 67 | if randomize { |
60 | krates.shuffle(&mut thread_rng()); | 68 | shuffle(&mut rng, &mut krates); |
61 | } | 69 | } |
62 | for krate in krates { | 70 | for krate in krates { |
63 | let module = krate.root_module(db).expect("crate without root module"); | 71 | let module = krate.root_module(db).expect("crate without root module"); |
@@ -72,7 +80,7 @@ pub fn analysis_stats( | |||
72 | } | 80 | } |
73 | 81 | ||
74 | if randomize { | 82 | if randomize { |
75 | visit_queue.shuffle(&mut thread_rng()); | 83 | shuffle(&mut rng, &mut visit_queue); |
76 | } | 84 | } |
77 | 85 | ||
78 | eprintln!("Crates in this dir: {}", num_crates); | 86 | eprintln!("Crates in this dir: {}", num_crates); |
@@ -110,7 +118,7 @@ pub fn analysis_stats( | |||
110 | ); | 118 | ); |
111 | 119 | ||
112 | if randomize { | 120 | if randomize { |
113 | funcs.shuffle(&mut thread_rng()); | 121 | shuffle(&mut rng, &mut funcs); |
114 | } | 122 | } |
115 | 123 | ||
116 | let mut bar = match verbosity { | 124 | let mut bar = match verbosity { |
@@ -306,3 +314,10 @@ pub fn analysis_stats( | |||
306 | 314 | ||
307 | Ok(()) | 315 | Ok(()) |
308 | } | 316 | } |
317 | |||
318 | fn shuffle<T>(rng: &mut Rand32, slice: &mut [T]) { | ||
319 | for i in (1..slice.len()).rev() { | ||
320 | let idx = rng.rand_range(0..i as u32) as usize; | ||
321 | slice.swap(idx, i - 1) | ||
322 | } | ||
323 | } | ||