@@ -77,8 +77,13 @@ impl FlycheckHandle {
77
77
}
78
78
79
79
/// Schedule a re-start of the cargo check worker.
80
- pub fn update ( & self ) {
81
- self . sender . send ( Restart ) . unwrap ( ) ;
80
+ pub fn restart ( & self ) {
81
+ self . sender . send ( Restart :: Yes ) . unwrap ( ) ;
82
+ }
83
+
84
+ /// Stop this cargo check worker.
85
+ pub fn cancel ( & self ) {
86
+ self . sender . send ( Restart :: No ) . unwrap ( ) ;
82
87
}
83
88
84
89
pub fn id ( & self ) -> usize {
@@ -122,7 +127,10 @@ pub enum Progress {
122
127
DidCancel ,
123
128
}
124
129
125
- struct Restart ;
130
+ enum Restart {
131
+ Yes ,
132
+ No ,
133
+ }
126
134
127
135
struct FlycheckActor {
128
136
id : usize ,
@@ -149,6 +157,7 @@ impl FlycheckActor {
149
157
config : FlycheckConfig ,
150
158
workspace_root : AbsPathBuf ,
151
159
) -> FlycheckActor {
160
+ tracing:: info!( %id, ?workspace_root, "Spawning flycheck" ) ;
152
161
FlycheckActor { id, sender, config, workspace_root, cargo_handle : None }
153
162
}
154
163
fn progress ( & self , progress : Progress ) {
@@ -164,10 +173,13 @@ impl FlycheckActor {
164
173
fn run ( mut self , inbox : Receiver < Restart > ) {
165
174
while let Some ( event) = self . next_event ( & inbox) {
166
175
match event {
167
- Event :: Restart ( Restart ) => {
176
+ Event :: Restart ( Restart :: No ) => {
177
+ self . cancel_check_process ( ) ;
178
+ }
179
+ Event :: Restart ( Restart :: Yes ) => {
168
180
// Cancel the previously spawned process
169
181
self . cancel_check_process ( ) ;
170
- while let Ok ( Restart ) = inbox. recv_timeout ( Duration :: from_millis ( 50 ) ) { }
182
+ while let Ok ( _ ) = inbox. recv_timeout ( Duration :: from_millis ( 50 ) ) { }
171
183
172
184
let command = self . check_command ( ) ;
173
185
tracing:: debug!( ?command, "will restart flycheck" ) ;
@@ -223,6 +235,10 @@ impl FlycheckActor {
223
235
224
236
fn cancel_check_process ( & mut self ) {
225
237
if let Some ( cargo_handle) = self . cargo_handle . take ( ) {
238
+ tracing:: debug!(
239
+ command = ?self . check_command( ) ,
240
+ "did cancel flycheck"
241
+ ) ;
226
242
cargo_handle. cancel ( ) ;
227
243
self . progress ( Progress :: DidCancel ) ;
228
244
}
0 commit comments