aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_flycheck/src/lib.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-06-25 07:01:03 +0100
committerAleksey Kladov <[email protected]>2020-06-25 07:01:03 +0100
commit874a5f80c74851aa142a196be49b73f55bd1c619 (patch)
tree0ff97656e30c9b1fe3c4bb96b0171f33890c11ee /crates/ra_flycheck/src/lib.rs
parent76a530242a12f75e2a8456f952cef07e2d564f67 (diff)
Scale progress down
There are two reasons why we don't want a generic ra_progress crate just yet: *First*, it introduces a common interface between separate components, and that is usually undesirable (b/c components start to fit the interface, rather than doing what makes most sense for each particular component). *Second*, it introduces a separate async channel for progress, which makes it harder to correlate progress reports with the work done. Ie, when we see 100% progress, it's not blindly obvious that the work has actually finished, we might have some pending messages still.
Diffstat (limited to 'crates/ra_flycheck/src/lib.rs')
-rw-r--r--crates/ra_flycheck/src/lib.rs50
1 files changed, 23 insertions, 27 deletions
diff --git a/crates/ra_flycheck/src/lib.rs b/crates/ra_flycheck/src/lib.rs
index 7b9f48eb0..0e2ee8698 100644
--- a/crates/ra_flycheck/src/lib.rs
+++ b/crates/ra_flycheck/src/lib.rs
@@ -17,9 +17,6 @@ pub use cargo_metadata::diagnostic::{
17 Applicability, Diagnostic, DiagnosticLevel, DiagnosticSpan, DiagnosticSpanMacroExpansion, 17 Applicability, Diagnostic, DiagnosticLevel, DiagnosticSpan, DiagnosticSpanMacroExpansion,
18}; 18};
19 19
20type Progress = ra_progress::Progress<(), String>;
21type ProgressSource = ra_progress::ProgressSource<(), String>;
22
23#[derive(Clone, Debug, PartialEq, Eq)] 20#[derive(Clone, Debug, PartialEq, Eq)]
24pub enum FlycheckConfig { 21pub enum FlycheckConfig {
25 CargoCommand { 22 CargoCommand {
@@ -59,15 +56,11 @@ pub struct Flycheck {
59} 56}
60 57
61impl Flycheck { 58impl Flycheck {
62 pub fn new( 59 pub fn new(config: FlycheckConfig, workspace_root: PathBuf) -> Flycheck {
63 config: FlycheckConfig,
64 workspace_root: PathBuf,
65 progress_src: ProgressSource,
66 ) -> Flycheck {
67 let (task_send, task_recv) = unbounded::<CheckTask>(); 60 let (task_send, task_recv) = unbounded::<CheckTask>();
68 let (cmd_send, cmd_recv) = unbounded::<CheckCommand>(); 61 let (cmd_send, cmd_recv) = unbounded::<CheckCommand>();
69 let handle = jod_thread::spawn(move || { 62 let handle = jod_thread::spawn(move || {
70 FlycheckThread::new(config, workspace_root, progress_src).run(&task_send, &cmd_recv); 63 FlycheckThread::new(config, workspace_root).run(&task_send, &cmd_recv);
71 }); 64 });
72 Flycheck { task_recv, cmd_send, handle } 65 Flycheck { task_recv, cmd_send, handle }
73 } 66 }
@@ -85,6 +78,16 @@ pub enum CheckTask {
85 78
86 /// Request adding a diagnostic with fixes included to a file 79 /// Request adding a diagnostic with fixes included to a file
87 AddDiagnostic { workspace_root: PathBuf, diagnostic: Diagnostic }, 80 AddDiagnostic { workspace_root: PathBuf, diagnostic: Diagnostic },
81
82 /// Request check progress notification to client
83 Status(Status),
84}
85
86#[derive(Debug)]
87pub enum Status {
88 Being,
89 Progress(String),
90 End,
88} 91}
89 92
90pub enum CheckCommand { 93pub enum CheckCommand {
@@ -96,8 +99,6 @@ struct FlycheckThread {
96 config: FlycheckConfig, 99 config: FlycheckConfig,
97 workspace_root: PathBuf, 100 workspace_root: PathBuf,
98 last_update_req: Option<Instant>, 101 last_update_req: Option<Instant>,
99 progress_src: ProgressSource,
100 progress: Option<Progress>,
101 // XXX: drop order is significant 102 // XXX: drop order is significant
102 message_recv: Receiver<CheckEvent>, 103 message_recv: Receiver<CheckEvent>,
103 /// WatchThread exists to wrap around the communication needed to be able to 104 /// WatchThread exists to wrap around the communication needed to be able to
@@ -109,17 +110,11 @@ struct FlycheckThread {
109} 110}
110 111
111impl FlycheckThread { 112impl FlycheckThread {
112 fn new( 113 fn new(config: FlycheckConfig, workspace_root: PathBuf) -> FlycheckThread {
113 config: FlycheckConfig,
114 workspace_root: PathBuf,
115 progress_src: ProgressSource,
116 ) -> FlycheckThread {
117 FlycheckThread { 114 FlycheckThread {
118 config, 115 config,
119 workspace_root, 116 workspace_root,
120 progress_src,
121 last_update_req: None, 117 last_update_req: None,
122 progress: None,
123 message_recv: never(), 118 message_recv: never(),
124 check_process: None, 119 check_process: None,
125 } 120 }
@@ -157,9 +152,9 @@ impl FlycheckThread {
157 } 152 }
158 } 153 }
159 154
160 fn clean_previous_results(&mut self, task_send: &Sender<CheckTask>) { 155 fn clean_previous_results(&self, task_send: &Sender<CheckTask>) {
161 task_send.send(CheckTask::ClearDiagnostics).unwrap(); 156 task_send.send(CheckTask::ClearDiagnostics).unwrap();
162 self.progress = None; 157 task_send.send(CheckTask::Status(Status::End)).unwrap();
163 } 158 }
164 159
165 fn should_recheck(&mut self) -> bool { 160 fn should_recheck(&mut self) -> bool {
@@ -178,17 +173,18 @@ impl FlycheckThread {
178 } 173 }
179 } 174 }
180 175
181 fn handle_message(&mut self, msg: CheckEvent, task_send: &Sender<CheckTask>) { 176 fn handle_message(&self, msg: CheckEvent, task_send: &Sender<CheckTask>) {
182 match msg { 177 match msg {
183 CheckEvent::Begin => { 178 CheckEvent::Begin => {
184 self.progress = Some(self.progress_src.begin(())); 179 task_send.send(CheckTask::Status(Status::Being)).unwrap();
180 }
181
182 CheckEvent::End => {
183 task_send.send(CheckTask::Status(Status::End)).unwrap();
185 } 184 }
186 CheckEvent::End => self.progress = None, 185
187 CheckEvent::Msg(Message::CompilerArtifact(msg)) => { 186 CheckEvent::Msg(Message::CompilerArtifact(msg)) => {
188 self.progress 187 task_send.send(CheckTask::Status(Status::Progress(msg.target.name))).unwrap();
189 .as_mut()
190 .expect("check process reported progress without the 'Begin' notification")
191 .report(msg.target.name);
192 } 188 }
193 189
194 CheckEvent::Msg(Message::CompilerMessage(msg)) => { 190 CheckEvent::Msg(Message::CompilerMessage(msg)) => {