aboutsummaryrefslogtreecommitdiff
path: root/crates/flycheck
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-06-25 08:26:13 +0100
committerAleksey Kladov <[email protected]>2020-06-25 08:27:59 +0100
commit941d4bfa53ebf4dd683889c2151544bcc3095073 (patch)
tree5cc950031a414bb0a9d9580b6f4416a34dc02e14 /crates/flycheck
parent5d401092f004f7f61e622b6c1d19a32799cbe31f (diff)
Simplify
Diffstat (limited to 'crates/flycheck')
-rw-r--r--crates/flycheck/src/lib.rs21
1 files changed, 6 insertions, 15 deletions
diff --git a/crates/flycheck/src/lib.rs b/crates/flycheck/src/lib.rs
index 0f23e97f7..3e73cf6ff 100644
--- a/crates/flycheck/src/lib.rs
+++ b/crates/flycheck/src/lib.rs
@@ -49,7 +49,7 @@ impl fmt::Display for FlycheckConfig {
49#[derive(Debug)] 49#[derive(Debug)]
50pub struct FlycheckHandle { 50pub struct FlycheckHandle {
51 // XXX: drop order is significant 51 // XXX: drop order is significant
52 cmd_send: Sender<CheckCommand>, 52 cmd_send: Sender<Restart>,
53 handle: jod_thread::JoinHandle, 53 handle: jod_thread::JoinHandle,
54} 54}
55 55
@@ -59,7 +59,7 @@ impl FlycheckHandle {
59 config: FlycheckConfig, 59 config: FlycheckConfig,
60 workspace_root: PathBuf, 60 workspace_root: PathBuf,
61 ) -> FlycheckHandle { 61 ) -> FlycheckHandle {
62 let (cmd_send, cmd_recv) = unbounded::<CheckCommand>(); 62 let (cmd_send, cmd_recv) = unbounded::<Restart>();
63 let handle = jod_thread::spawn(move || { 63 let handle = jod_thread::spawn(move || {
64 FlycheckActor::new(sender, config, workspace_root).run(&cmd_recv); 64 FlycheckActor::new(sender, config, workspace_root).run(&cmd_recv);
65 }); 65 });
@@ -68,7 +68,7 @@ impl FlycheckHandle {
68 68
69 /// Schedule a re-start of the cargo check worker. 69 /// Schedule a re-start of the cargo check worker.
70 pub fn update(&self) { 70 pub fn update(&self) {
71 self.cmd_send.send(CheckCommand::Update).unwrap(); 71 self.cmd_send.send(Restart).unwrap();
72 } 72 }
73} 73}
74 74
@@ -91,10 +91,7 @@ pub enum Progress {
91 End, 91 End,
92} 92}
93 93
94enum CheckCommand { 94struct Restart;
95 /// Request re-start of check thread
96 Update,
97}
98 95
99struct FlycheckActor { 96struct FlycheckActor {
100 sender: Box<dyn Fn(Message) + Send>, 97 sender: Box<dyn Fn(Message) + Send>,
@@ -127,14 +124,14 @@ impl FlycheckActor {
127 } 124 }
128 } 125 }
129 126
130 fn run(&mut self, cmd_recv: &Receiver<CheckCommand>) { 127 fn run(&mut self, cmd_recv: &Receiver<Restart>) {
131 // If we rerun the thread, we need to discard the previous check results first 128 // If we rerun the thread, we need to discard the previous check results first
132 self.clean_previous_results(); 129 self.clean_previous_results();
133 130
134 loop { 131 loop {
135 select! { 132 select! {
136 recv(&cmd_recv) -> cmd => match cmd { 133 recv(&cmd_recv) -> cmd => match cmd {
137 Ok(cmd) => self.handle_command(cmd), 134 Ok(Restart) => self.last_update_req = Some(Instant::now()),
138 Err(RecvError) => { 135 Err(RecvError) => {
139 // Command channel has closed, so shut down 136 // Command channel has closed, so shut down
140 break; 137 break;
@@ -174,12 +171,6 @@ impl FlycheckActor {
174 false 171 false
175 } 172 }
176 173
177 fn handle_command(&mut self, cmd: CheckCommand) {
178 match cmd {
179 CheckCommand::Update => self.last_update_req = Some(Instant::now()),
180 }
181 }
182
183 fn handle_message(&self, msg: CheckEvent) { 174 fn handle_message(&self, msg: CheckEvent) {
184 match msg { 175 match msg {
185 CheckEvent::Begin => { 176 CheckEvent::Begin => {