diff options
Diffstat (limited to 'crates/ra_cli')
-rw-r--r-- | crates/ra_cli/Cargo.toml | 3 | ||||
-rw-r--r-- | crates/ra_cli/src/analysis_bench.rs | 6 | ||||
-rw-r--r-- | crates/ra_cli/src/analysis_stats.rs | 14 | ||||
-rw-r--r-- | crates/ra_cli/src/main.rs | 3 | ||||
-rw-r--r-- | crates/ra_cli/src/progress_report.rs | 120 |
5 files changed, 130 insertions, 16 deletions
diff --git a/crates/ra_cli/Cargo.toml b/crates/ra_cli/Cargo.toml index c9d3bdb77..c7e0d0f0f 100644 --- a/crates/ra_cli/Cargo.toml +++ b/crates/ra_cli/Cargo.toml | |||
@@ -8,10 +8,9 @@ publish = false | |||
8 | [dependencies] | 8 | [dependencies] |
9 | pico-args = "0.3.0" | 9 | pico-args = "0.3.0" |
10 | flexi_logger = "0.14.0" | 10 | flexi_logger = "0.14.0" |
11 | indicatif = "0.13.0" | ||
12 | 11 | ||
13 | ra_syntax = { path = "../ra_syntax" } | 12 | ra_syntax = { path = "../ra_syntax" } |
14 | ra_ide_api = { path = "../ra_ide_api" } | 13 | ra_ide = { path = "../ra_ide" } |
15 | ra_batch = { path = "../ra_batch" } | 14 | ra_batch = { path = "../ra_batch" } |
16 | ra_hir = { path = "../ra_hir" } | 15 | ra_hir = { path = "../ra_hir" } |
17 | ra_db = { path = "../ra_db" } | 16 | ra_db = { path = "../ra_db" } |
diff --git a/crates/ra_cli/src/analysis_bench.rs b/crates/ra_cli/src/analysis_bench.rs index 8bbe5d9e8..5485a38ff 100644 --- a/crates/ra_cli/src/analysis_bench.rs +++ b/crates/ra_cli/src/analysis_bench.rs | |||
@@ -10,7 +10,7 @@ use ra_db::{ | |||
10 | salsa::{Database, Durability}, | 10 | salsa::{Database, Durability}, |
11 | FileId, SourceDatabaseExt, | 11 | FileId, SourceDatabaseExt, |
12 | }; | 12 | }; |
13 | use ra_ide_api::{Analysis, AnalysisChange, AnalysisHost, FilePosition, LineCol}; | 13 | use ra_ide::{Analysis, AnalysisChange, AnalysisHost, FilePosition, LineCol}; |
14 | 14 | ||
15 | use crate::Result; | 15 | use crate::Result; |
16 | 16 | ||
@@ -91,7 +91,7 @@ fn do_work<F: Fn(&Analysis) -> T, T>(host: &mut AnalysisHost, file_id: FileId, w | |||
91 | { | 91 | { |
92 | let start = Instant::now(); | 92 | let start = Instant::now(); |
93 | eprint!("trivial change: "); | 93 | eprint!("trivial change: "); |
94 | host.raw_database().salsa_runtime().synthetic_write(Durability::LOW); | 94 | host.raw_database_mut().salsa_runtime_mut().synthetic_write(Durability::LOW); |
95 | work(&host.analysis()); | 95 | work(&host.analysis()); |
96 | eprintln!("{:?}", start.elapsed()); | 96 | eprintln!("{:?}", start.elapsed()); |
97 | } | 97 | } |
@@ -111,7 +111,7 @@ fn do_work<F: Fn(&Analysis) -> T, T>(host: &mut AnalysisHost, file_id: FileId, w | |||
111 | { | 111 | { |
112 | let start = Instant::now(); | 112 | let start = Instant::now(); |
113 | eprint!("const change: "); | 113 | eprint!("const change: "); |
114 | host.raw_database().salsa_runtime().synthetic_write(Durability::HIGH); | 114 | host.raw_database_mut().salsa_runtime_mut().synthetic_write(Durability::HIGH); |
115 | let res = work(&host.analysis()); | 115 | let res = work(&host.analysis()); |
116 | eprintln!("{:?}", start.elapsed()); | 116 | eprintln!("{:?}", start.elapsed()); |
117 | res | 117 | res |
diff --git a/crates/ra_cli/src/analysis_stats.rs b/crates/ra_cli/src/analysis_stats.rs index c4eb28245..9b1802a5f 100644 --- a/crates/ra_cli/src/analysis_stats.rs +++ b/crates/ra_cli/src/analysis_stats.rs | |||
@@ -6,7 +6,7 @@ use ra_db::SourceDatabaseExt; | |||
6 | use ra_hir::{AssocItem, Crate, HasSource, HirDisplay, ModuleDef, Ty, TypeWalk}; | 6 | use ra_hir::{AssocItem, Crate, HasSource, HirDisplay, ModuleDef, Ty, TypeWalk}; |
7 | use ra_syntax::AstNode; | 7 | use ra_syntax::AstNode; |
8 | 8 | ||
9 | use crate::{Result, Verbosity}; | 9 | use crate::{progress_report::ProgressReport, Result, Verbosity}; |
10 | 10 | ||
11 | pub fn run( | 11 | pub fn run( |
12 | verbosity: Verbosity, | 12 | verbosity: Verbosity, |
@@ -75,17 +75,11 @@ pub fn run( | |||
75 | println!("Item Collection: {:?}, {}", analysis_time.elapsed(), ra_prof::memory_usage()); | 75 | println!("Item Collection: {:?}, {}", analysis_time.elapsed(), ra_prof::memory_usage()); |
76 | 76 | ||
77 | let inference_time = Instant::now(); | 77 | let inference_time = Instant::now(); |
78 | let bar = match verbosity { | 78 | let mut bar = match verbosity { |
79 | Verbosity::Verbose | Verbosity::Normal => indicatif::ProgressBar::with_draw_target( | 79 | Verbosity::Verbose | Verbosity::Normal => ProgressReport::new(funcs.len() as u64), |
80 | funcs.len() as u64, | 80 | Verbosity::Quiet => ProgressReport::hidden(), |
81 | indicatif::ProgressDrawTarget::stderr_nohz(), | ||
82 | ), | ||
83 | Verbosity::Quiet => indicatif::ProgressBar::hidden(), | ||
84 | }; | 81 | }; |
85 | 82 | ||
86 | bar.set_style( | ||
87 | indicatif::ProgressStyle::default_bar().template("{wide_bar} {pos}/{len}\n{msg}"), | ||
88 | ); | ||
89 | bar.tick(); | 83 | bar.tick(); |
90 | let mut num_exprs = 0; | 84 | let mut num_exprs = 0; |
91 | let mut num_exprs_unknown = 0; | 85 | let mut num_exprs_unknown = 0; |
diff --git a/crates/ra_cli/src/main.rs b/crates/ra_cli/src/main.rs index a31fd5d6a..fe847e611 100644 --- a/crates/ra_cli/src/main.rs +++ b/crates/ra_cli/src/main.rs | |||
@@ -3,12 +3,13 @@ | |||
3 | mod analysis_stats; | 3 | mod analysis_stats; |
4 | mod analysis_bench; | 4 | mod analysis_bench; |
5 | mod help; | 5 | mod help; |
6 | mod progress_report; | ||
6 | 7 | ||
7 | use std::{error::Error, fmt::Write, io::Read}; | 8 | use std::{error::Error, fmt::Write, io::Read}; |
8 | 9 | ||
9 | use flexi_logger::Logger; | 10 | use flexi_logger::Logger; |
10 | use pico_args::Arguments; | 11 | use pico_args::Arguments; |
11 | use ra_ide_api::{file_structure, Analysis}; | 12 | use ra_ide::{file_structure, Analysis}; |
12 | use ra_prof::profile; | 13 | use ra_prof::profile; |
13 | use ra_syntax::{AstNode, SourceFile}; | 14 | use ra_syntax::{AstNode, SourceFile}; |
14 | 15 | ||
diff --git a/crates/ra_cli/src/progress_report.rs b/crates/ra_cli/src/progress_report.rs new file mode 100644 index 000000000..31867a1e9 --- /dev/null +++ b/crates/ra_cli/src/progress_report.rs | |||
@@ -0,0 +1,120 @@ | |||
1 | //! A simple progress bar | ||
2 | //! | ||
3 | //! A single thread non-optimized progress bar | ||
4 | use std::io::Write; | ||
5 | |||
6 | /// A Simple ASCII Progress Bar | ||
7 | pub struct ProgressReport { | ||
8 | curr: f32, | ||
9 | text: String, | ||
10 | hidden: bool, | ||
11 | |||
12 | len: u64, | ||
13 | pos: u64, | ||
14 | msg: String, | ||
15 | } | ||
16 | |||
17 | impl ProgressReport { | ||
18 | pub fn new(len: u64) -> ProgressReport { | ||
19 | ProgressReport { | ||
20 | curr: 0.0, | ||
21 | text: String::new(), | ||
22 | hidden: false, | ||
23 | len, | ||
24 | pos: 0, | ||
25 | msg: String::new(), | ||
26 | } | ||
27 | } | ||
28 | |||
29 | pub fn hidden() -> ProgressReport { | ||
30 | ProgressReport { | ||
31 | curr: 0.0, | ||
32 | text: String::new(), | ||
33 | hidden: true, | ||
34 | len: 0, | ||
35 | pos: 0, | ||
36 | msg: String::new(), | ||
37 | } | ||
38 | } | ||
39 | |||
40 | pub fn set_message(&mut self, msg: &str) { | ||
41 | self.msg = msg.to_string(); | ||
42 | self.tick(); | ||
43 | } | ||
44 | |||
45 | pub fn println<I: Into<String>>(&mut self, msg: I) { | ||
46 | self.clear(); | ||
47 | println!("{}", msg.into()); | ||
48 | self.tick(); | ||
49 | } | ||
50 | |||
51 | pub fn inc(&mut self, delta: u64) { | ||
52 | self.pos += delta; | ||
53 | if self.len == 0 { | ||
54 | self.set_value(0.0) | ||
55 | } else { | ||
56 | self.set_value((self.pos as f32) / (self.len as f32)) | ||
57 | } | ||
58 | self.tick(); | ||
59 | } | ||
60 | |||
61 | pub fn finish_and_clear(&mut self) { | ||
62 | self.clear(); | ||
63 | } | ||
64 | |||
65 | pub fn tick(&mut self) { | ||
66 | if self.hidden { | ||
67 | return; | ||
68 | } | ||
69 | let percent = (self.curr * 100.0) as u32; | ||
70 | let text = format!("{}/{} {:3>}% {}", self.pos, self.len, percent, self.msg); | ||
71 | self.update_text(&text); | ||
72 | } | ||
73 | |||
74 | fn update_text(&mut self, text: &str) { | ||
75 | // Get length of common portion | ||
76 | let mut common_prefix_length = 0; | ||
77 | let common_length = usize::min(self.text.len(), text.len()); | ||
78 | |||
79 | while common_prefix_length < common_length | ||
80 | && text.chars().nth(common_prefix_length).unwrap() | ||
81 | == self.text.chars().nth(common_prefix_length).unwrap() | ||
82 | { | ||
83 | common_prefix_length += 1; | ||
84 | } | ||
85 | |||
86 | // Backtrack to the first differing character | ||
87 | let mut output = String::new(); | ||
88 | output += &'\x08'.to_string().repeat(self.text.len() - common_prefix_length); | ||
89 | // Output new suffix | ||
90 | output += &text[common_prefix_length..text.len()]; | ||
91 | |||
92 | // If the new text is shorter than the old one: delete overlapping characters | ||
93 | if let Some(overlap_count) = self.text.len().checked_sub(text.len()) { | ||
94 | if overlap_count > 0 { | ||
95 | output += &" ".repeat(overlap_count); | ||
96 | output += &"\x08".repeat(overlap_count); | ||
97 | } | ||
98 | } | ||
99 | |||
100 | let _ = std::io::stdout().write(output.as_bytes()); | ||
101 | let _ = std::io::stdout().flush(); | ||
102 | self.text = text.to_string(); | ||
103 | } | ||
104 | |||
105 | fn set_value(&mut self, value: f32) { | ||
106 | self.curr = f32::max(0.0, f32::min(1.0, value)); | ||
107 | } | ||
108 | |||
109 | fn clear(&mut self) { | ||
110 | if self.hidden { | ||
111 | return; | ||
112 | } | ||
113 | |||
114 | // Fill all last text to space and return the cursor | ||
115 | let spaces = " ".repeat(self.text.len()); | ||
116 | let backspaces = "\x08".repeat(self.text.len()); | ||
117 | print!("{}{}{}", backspaces, spaces, backspaces); | ||
118 | self.text = String::new(); | ||
119 | } | ||
120 | } | ||