diff options
author | Aleksey Kladov <[email protected]> | 2020-06-25 08:19:01 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-06-25 08:19:01 +0100 |
commit | 5d401092f004f7f61e622b6c1d19a32799cbe31f (patch) | |
tree | edad60445369f25afd324a7915503c133ffcd1bb /crates/flycheck/src | |
parent | 0ec5d4f55c6a5ac3fadcd48ae17b70379aba17fa (diff) |
Minor rename
Diffstat (limited to 'crates/flycheck/src')
-rw-r--r-- | crates/flycheck/src/lib.rs | 57 |
1 files changed, 29 insertions, 28 deletions
diff --git a/crates/flycheck/src/lib.rs b/crates/flycheck/src/lib.rs index af75adbe2..0f23e97f7 100644 --- a/crates/flycheck/src/lib.rs +++ b/crates/flycheck/src/lib.rs | |||
@@ -10,7 +10,6 @@ use std::{ | |||
10 | time::Instant, | 10 | time::Instant, |
11 | }; | 11 | }; |
12 | 12 | ||
13 | use cargo_metadata::Message; | ||
14 | use crossbeam_channel::{never, select, unbounded, Receiver, RecvError, Sender}; | 13 | use crossbeam_channel::{never, select, unbounded, Receiver, RecvError, Sender}; |
15 | 14 | ||
16 | pub use cargo_metadata::diagnostic::{ | 15 | pub use cargo_metadata::diagnostic::{ |
@@ -51,12 +50,12 @@ impl fmt::Display for FlycheckConfig { | |||
51 | pub struct FlycheckHandle { | 50 | pub struct FlycheckHandle { |
52 | // XXX: drop order is significant | 51 | // XXX: drop order is significant |
53 | cmd_send: Sender<CheckCommand>, | 52 | cmd_send: Sender<CheckCommand>, |
54 | handle: jod_thread::JoinHandle<()>, | 53 | handle: jod_thread::JoinHandle, |
55 | } | 54 | } |
56 | 55 | ||
57 | impl FlycheckHandle { | 56 | impl FlycheckHandle { |
58 | pub fn spawn( | 57 | pub fn spawn( |
59 | sender: Box<dyn Fn(CheckTask) + Send>, | 58 | sender: Box<dyn Fn(Message) + Send>, |
60 | config: FlycheckConfig, | 59 | config: FlycheckConfig, |
61 | workspace_root: PathBuf, | 60 | workspace_root: PathBuf, |
62 | ) -> FlycheckHandle { | 61 | ) -> FlycheckHandle { |
@@ -74,7 +73,7 @@ impl FlycheckHandle { | |||
74 | } | 73 | } |
75 | 74 | ||
76 | #[derive(Debug)] | 75 | #[derive(Debug)] |
77 | pub enum CheckTask { | 76 | pub enum Message { |
78 | /// Request a clearing of all cached diagnostics from the check watcher | 77 | /// Request a clearing of all cached diagnostics from the check watcher |
79 | ClearDiagnostics, | 78 | ClearDiagnostics, |
80 | 79 | ||
@@ -82,23 +81,23 @@ pub enum CheckTask { | |||
82 | AddDiagnostic { workspace_root: PathBuf, diagnostic: Diagnostic }, | 81 | AddDiagnostic { workspace_root: PathBuf, diagnostic: Diagnostic }, |
83 | 82 | ||
84 | /// Request check progress notification to client | 83 | /// Request check progress notification to client |
85 | Status(Status), | 84 | Progress(Progress), |
86 | } | 85 | } |
87 | 86 | ||
88 | #[derive(Debug)] | 87 | #[derive(Debug)] |
89 | pub enum Status { | 88 | pub enum Progress { |
90 | Being, | 89 | Being, |
91 | Progress(String), | 90 | DidCheckCrate(String), |
92 | End, | 91 | End, |
93 | } | 92 | } |
94 | 93 | ||
95 | pub enum CheckCommand { | 94 | enum CheckCommand { |
96 | /// Request re-start of check thread | 95 | /// Request re-start of check thread |
97 | Update, | 96 | Update, |
98 | } | 97 | } |
99 | 98 | ||
100 | struct FlycheckActor { | 99 | struct FlycheckActor { |
101 | sender: Box<dyn Fn(CheckTask) + Send>, | 100 | sender: Box<dyn Fn(Message) + Send>, |
102 | config: FlycheckConfig, | 101 | config: FlycheckConfig, |
103 | workspace_root: PathBuf, | 102 | workspace_root: PathBuf, |
104 | last_update_req: Option<Instant>, | 103 | last_update_req: Option<Instant>, |
@@ -109,12 +108,12 @@ struct FlycheckActor { | |||
109 | /// doesn't provide a way to read sub-process output without blocking, so we | 108 | /// doesn't provide a way to read sub-process output without blocking, so we |
110 | /// have to wrap sub-processes output handling in a thread and pass messages | 109 | /// have to wrap sub-processes output handling in a thread and pass messages |
111 | /// back over a channel. | 110 | /// back over a channel. |
112 | check_process: Option<jod_thread::JoinHandle<()>>, | 111 | check_process: Option<jod_thread::JoinHandle>, |
113 | } | 112 | } |
114 | 113 | ||
115 | impl FlycheckActor { | 114 | impl FlycheckActor { |
116 | fn new( | 115 | fn new( |
117 | sender: Box<dyn Fn(CheckTask) + Send>, | 116 | sender: Box<dyn Fn(Message) + Send>, |
118 | config: FlycheckConfig, | 117 | config: FlycheckConfig, |
119 | workspace_root: PathBuf, | 118 | workspace_root: PathBuf, |
120 | ) -> FlycheckActor { | 119 | ) -> FlycheckActor { |
@@ -154,15 +153,15 @@ impl FlycheckActor { | |||
154 | 153 | ||
155 | if self.should_recheck() { | 154 | if self.should_recheck() { |
156 | self.last_update_req = None; | 155 | self.last_update_req = None; |
157 | self.send(CheckTask::ClearDiagnostics); | 156 | self.send(Message::ClearDiagnostics); |
158 | self.restart_check_process(); | 157 | self.restart_check_process(); |
159 | } | 158 | } |
160 | } | 159 | } |
161 | } | 160 | } |
162 | 161 | ||
163 | fn clean_previous_results(&self) { | 162 | fn clean_previous_results(&self) { |
164 | self.send(CheckTask::ClearDiagnostics); | 163 | self.send(Message::ClearDiagnostics); |
165 | self.send(CheckTask::Status(Status::End)); | 164 | self.send(Message::Progress(Progress::End)); |
166 | } | 165 | } |
167 | 166 | ||
168 | fn should_recheck(&mut self) -> bool { | 167 | fn should_recheck(&mut self) -> bool { |
@@ -184,28 +183,28 @@ impl FlycheckActor { | |||
184 | fn handle_message(&self, msg: CheckEvent) { | 183 | fn handle_message(&self, msg: CheckEvent) { |
185 | match msg { | 184 | match msg { |
186 | CheckEvent::Begin => { | 185 | CheckEvent::Begin => { |
187 | self.send(CheckTask::Status(Status::Being)); | 186 | self.send(Message::Progress(Progress::Being)); |
188 | } | 187 | } |
189 | 188 | ||
190 | CheckEvent::End => { | 189 | CheckEvent::End => { |
191 | self.send(CheckTask::Status(Status::End)); | 190 | self.send(Message::Progress(Progress::End)); |
192 | } | 191 | } |
193 | 192 | ||
194 | CheckEvent::Msg(Message::CompilerArtifact(msg)) => { | 193 | CheckEvent::Msg(cargo_metadata::Message::CompilerArtifact(msg)) => { |
195 | self.send(CheckTask::Status(Status::Progress(msg.target.name))); | 194 | self.send(Message::Progress(Progress::DidCheckCrate(msg.target.name))); |
196 | } | 195 | } |
197 | 196 | ||
198 | CheckEvent::Msg(Message::CompilerMessage(msg)) => { | 197 | CheckEvent::Msg(cargo_metadata::Message::CompilerMessage(msg)) => { |
199 | self.send(CheckTask::AddDiagnostic { | 198 | self.send(Message::AddDiagnostic { |
200 | workspace_root: self.workspace_root.clone(), | 199 | workspace_root: self.workspace_root.clone(), |
201 | diagnostic: msg.message, | 200 | diagnostic: msg.message, |
202 | }); | 201 | }); |
203 | } | 202 | } |
204 | 203 | ||
205 | CheckEvent::Msg(Message::BuildScriptExecuted(_msg)) => {} | 204 | CheckEvent::Msg(cargo_metadata::Message::BuildScriptExecuted(_)) |
206 | CheckEvent::Msg(Message::BuildFinished(_)) => {} | 205 | | CheckEvent::Msg(cargo_metadata::Message::BuildFinished(_)) |
207 | CheckEvent::Msg(Message::TextLine(_)) => {} | 206 | | CheckEvent::Msg(cargo_metadata::Message::TextLine(_)) |
208 | CheckEvent::Msg(Message::Unknown) => {} | 207 | | CheckEvent::Msg(cargo_metadata::Message::Unknown) => {} |
209 | } | 208 | } |
210 | } | 209 | } |
211 | 210 | ||
@@ -256,9 +255,11 @@ impl FlycheckActor { | |||
256 | let res = run_cargo(cmd, &mut |message| { | 255 | let res = run_cargo(cmd, &mut |message| { |
257 | // Skip certain kinds of messages to only spend time on what's useful | 256 | // Skip certain kinds of messages to only spend time on what's useful |
258 | match &message { | 257 | match &message { |
259 | Message::CompilerArtifact(artifact) if artifact.fresh => return true, | 258 | cargo_metadata::Message::CompilerArtifact(artifact) if artifact.fresh => { |
260 | Message::BuildScriptExecuted(_) => return true, | 259 | return true |
261 | Message::Unknown => return true, | 260 | } |
261 | cargo_metadata::Message::BuildScriptExecuted(_) | ||
262 | | cargo_metadata::Message::Unknown => return true, | ||
262 | _ => {} | 263 | _ => {} |
263 | } | 264 | } |
264 | 265 | ||
@@ -278,7 +279,7 @@ impl FlycheckActor { | |||
278 | })) | 279 | })) |
279 | } | 280 | } |
280 | 281 | ||
281 | fn send(&self, check_task: CheckTask) { | 282 | fn send(&self, check_task: Message) { |
282 | (self.sender)(check_task) | 283 | (self.sender)(check_task) |
283 | } | 284 | } |
284 | } | 285 | } |