@@ -89,8 +89,9 @@ impl FlycheckHandle {
89
89
sender : Box < dyn Fn ( Message ) + Send > ,
90
90
config : FlycheckConfig ,
91
91
workspace_root : AbsPathBuf ,
92
+ project_file : AbsPathBuf ,
92
93
) -> FlycheckHandle {
93
- let actor = FlycheckActor :: new ( id, sender, config, workspace_root) ;
94
+ let actor = FlycheckActor :: new ( id, sender, config, workspace_root, project_file ) ;
94
95
let ( sender, receiver) = unbounded :: < StateChange > ( ) ;
95
96
let thread = stdx:: thread:: Builder :: new ( stdx:: thread:: ThreadIntent :: Worker )
96
97
. name ( "Flycheck" . to_owned ( ) )
@@ -100,8 +101,8 @@ impl FlycheckHandle {
100
101
}
101
102
102
103
/// Schedule a re-start of the cargo check worker.
103
- pub fn restart ( & self ) {
104
- self . sender . send ( StateChange :: Restart ) . unwrap ( ) ;
104
+ pub fn restart ( & self , saved_file : Option < AbsPathBuf > ) {
105
+ self . sender . send ( StateChange :: Restart { saved_file } ) . unwrap ( ) ;
105
106
}
106
107
107
108
/// Stop this cargo check worker.
@@ -152,7 +153,7 @@ pub enum Progress {
152
153
}
153
154
154
155
enum StateChange {
155
- Restart ,
156
+ Restart { saved_file : Option < AbsPathBuf > } ,
156
157
Cancel ,
157
158
}
158
159
@@ -165,6 +166,8 @@ struct FlycheckActor {
165
166
/// Either the workspace root of the workspace we are flychecking,
166
167
/// or the project root of the project.
167
168
root : AbsPathBuf ,
169
+ /// The Cargo.toml or rust-project.json file of the project.
170
+ project_file : AbsPathBuf ,
168
171
/// CargoHandle exists to wrap around the communication needed to be able to
169
172
/// run `cargo check` without blocking. Currently the Rust standard library
170
173
/// doesn't provide a way to read sub-process output without blocking, so we
@@ -184,9 +187,17 @@ impl FlycheckActor {
184
187
sender : Box < dyn Fn ( Message ) + Send > ,
185
188
config : FlycheckConfig ,
186
189
workspace_root : AbsPathBuf ,
190
+ project_file : AbsPathBuf ,
187
191
) -> FlycheckActor {
188
192
tracing:: info!( %id, ?workspace_root, "Spawning flycheck" ) ;
189
- FlycheckActor { id, sender, config, root : workspace_root, command_handle : None }
193
+ FlycheckActor {
194
+ id,
195
+ sender,
196
+ config,
197
+ root : workspace_root,
198
+ project_file,
199
+ command_handle : None ,
200
+ }
190
201
}
191
202
192
203
fn report_progress ( & self , progress : Progress ) {
@@ -212,7 +223,7 @@ impl FlycheckActor {
212
223
tracing:: debug!( flycheck_id = self . id, "flycheck cancelled" ) ;
213
224
self . cancel_check_process ( ) ;
214
225
}
215
- Event :: RequestStateChange ( StateChange :: Restart ) => {
226
+ Event :: RequestStateChange ( StateChange :: Restart { saved_file } ) => {
216
227
// Cancel the previously spawned process
217
228
self . cancel_check_process ( ) ;
218
229
while let Ok ( restart) = inbox. recv_timeout ( Duration :: from_millis ( 50 ) ) {
@@ -222,7 +233,7 @@ impl FlycheckActor {
222
233
}
223
234
}
224
235
225
- let command = self . check_command ( ) ;
236
+ let command = self . check_command ( saved_file ) ;
226
237
let formatted_command = format ! ( "{:?}" , command) ;
227
238
228
239
tracing:: debug!( ?command, "will restart flycheck" ) ;
@@ -296,8 +307,10 @@ impl FlycheckActor {
296
307
}
297
308
}
298
309
299
- fn check_command ( & self ) -> Command {
300
- let ( mut cmd, args) = match & self . config {
310
+ fn check_command ( & self , _saved_file : Option < AbsPathBuf > ) -> Command {
311
+ // FIXME: Figure out the story for exposing the saved file to the custom flycheck command
312
+ // as it can be absent
313
+ match & self . config {
301
314
FlycheckConfig :: CargoCommand {
302
315
command,
303
316
target_triples,
@@ -312,7 +325,7 @@ impl FlycheckActor {
312
325
let mut cmd = Command :: new ( toolchain:: cargo ( ) ) ;
313
326
cmd. arg ( command) ;
314
327
cmd. current_dir ( & self . root ) ;
315
- cmd. arg ( "--workspace" ) ;
328
+ cmd. args ( & [ "--workspace" , "--manifest-path" ] ) . arg ( self . project_file . as_os_str ( ) ) ;
316
329
317
330
cmd. arg ( if * ansi_color_output {
318
331
"--message-format=json-diagnostic-rendered-ansi"
@@ -341,7 +354,8 @@ impl FlycheckActor {
341
354
}
342
355
}
343
356
cmd. envs ( extra_env) ;
344
- ( cmd, extra_args)
357
+ cmd. args ( extra_args) ;
358
+ cmd
345
359
}
346
360
FlycheckConfig :: CustomCommand {
347
361
command,
@@ -352,30 +366,24 @@ impl FlycheckActor {
352
366
} => {
353
367
let mut cmd = Command :: new ( command) ;
354
368
cmd. envs ( extra_env) ;
369
+ args. iter ( ) . for_each ( |arg| {
370
+ match invocation_strategy {
371
+ InvocationStrategy :: Once => cmd. arg ( arg) ,
372
+ InvocationStrategy :: PerWorkspace => cmd. arg ( arg. replace (
373
+ "$manifest_path" ,
374
+ & self . project_file . as_os_str ( ) . to_string_lossy ( ) ,
375
+ ) ) ,
376
+ } ;
377
+ } ) ;
355
378
356
379
match invocation_location {
357
- InvocationLocation :: Workspace => {
358
- match invocation_strategy {
359
- InvocationStrategy :: Once => {
360
- cmd. current_dir ( & self . root ) ;
361
- }
362
- InvocationStrategy :: PerWorkspace => {
363
- // FIXME: cmd.current_dir(&affected_workspace);
364
- cmd. current_dir ( & self . root ) ;
365
- }
366
- }
367
- }
368
- InvocationLocation :: Root ( root) => {
369
- cmd. current_dir ( root) ;
370
- }
371
- }
380
+ InvocationLocation :: Workspace => cmd. current_dir ( & self . root ) ,
381
+ InvocationLocation :: Root ( root) => cmd. current_dir ( root) ,
382
+ } ;
372
383
373
- ( cmd, args )
384
+ cmd
374
385
}
375
- } ;
376
-
377
- cmd. args ( args) ;
378
- cmd
386
+ }
379
387
}
380
388
381
389
fn send ( & self , check_task : Message ) {
0 commit comments