@@ -168,6 +168,10 @@ pub(crate) struct FlycheckHandle {
168168 _thread : stdx:: thread:: JoinHandle ,
169169 id : usize ,
170170 generation : AtomicUsize ,
171+
172+ /// Bit hacky, but this lets us force the use of restart_for_package when the flycheck
173+ /// configuration does not support restart_workspace.
174+ cannot_run_workspace : bool ,
171175}
172176
173177impl FlycheckHandle {
@@ -193,12 +197,21 @@ impl FlycheckHandle {
193197 manifest_path,
194198 ws_target_dir,
195199 ) ;
200+
201+ let cannot_run_workspace = actor. cannot_run_workspace ( ) ;
202+
196203 let ( sender, receiver) = unbounded :: < StateChange > ( ) ;
197204 let thread =
198205 stdx:: thread:: Builder :: new ( stdx:: thread:: ThreadIntent :: Worker , format ! ( "Flycheck{id}" ) )
199206 . spawn ( move || actor. run ( receiver) )
200207 . expect ( "failed to spawn thread" ) ;
201- FlycheckHandle { id, generation : generation. into ( ) , sender, _thread : thread }
208+ FlycheckHandle {
209+ id,
210+ generation : generation. into ( ) ,
211+ sender,
212+ _thread : thread,
213+ cannot_run_workspace,
214+ }
202215 }
203216
204217 /// Schedule a re-start of the cargo check worker to do a workspace wide check.
@@ -214,6 +227,10 @@ impl FlycheckHandle {
214227 . unwrap ( ) ;
215228 }
216229
230+ pub ( crate ) fn cannot_run_workspace ( & self ) -> bool {
231+ self . cannot_run_workspace
232+ }
233+
217234 /// Schedule a re-start of the cargo check worker to do a package wide check.
218235 pub ( crate ) fn restart_for_package (
219236 & self ,
@@ -785,8 +802,15 @@ impl FlycheckActor {
785802 ) -> Option < Command > {
786803 let label = match scope {
787804 FlycheckScope :: Workspace => {
788- // self.config_json.workspace_template.as_ref().map(|x| x.to_command())
789- return None ;
805+ // If the template doesn't contain {label}, then it works for restarting all.
806+ //
807+ // Might be nice to have: self.config_json.workspace_template.as_ref().map(|x| x.to_command())
808+ // But for now this works.
809+ //
810+ let template = self . config_json . single_template . as_ref ( ) ?;
811+ let subs =
812+ Substitutions { label : None , saved_file : saved_file. map ( |x| x. as_str ( ) ) } ;
813+ return subs. substitute ( template, self . root . as_path ( ) , & FxHashMap :: default ( ) ) ;
790814 }
791815 FlycheckScope :: Package { package : PackageSpecifier :: BuildInfo { label } , .. } => {
792816 label. as_str ( )
@@ -802,6 +826,11 @@ impl FlycheckActor {
802826 subs. substitute ( template, self . root . as_path ( ) , & FxHashMap :: default ( ) )
803827 }
804828
829+ fn cannot_run_workspace ( & self ) -> bool {
830+ let fake_path = self . root . join ( "fake.rs" ) ;
831+ self . check_command ( & FlycheckScope :: Workspace , Some ( & fake_path) , None ) . is_none ( )
832+ }
833+
805834 /// Construct a `Command` object for checking the user's code. If the user
806835 /// has specified a custom command with placeholders that we cannot fill,
807836 /// return None.
0 commit comments