Skip to content

Commit b6e93b8

Browse files
committed
flycheck.cannot_run_workspace
1 parent 4d92a42 commit b6e93b8

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

crates/rust-analyzer/src/flycheck.rs

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

173177
impl 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.

crates/rust-analyzer/src/handlers/notification.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ fn run_flycheck(state: &mut GlobalState, vfs_path: VfsPath) -> bool {
467467
// Find and trigger corresponding flychecks
468468
'flychecks: for flycheck in world.flycheck.iter() {
469469
for (id, _) in workspace_ids.clone() {
470-
if id == flycheck.id() {
470+
if id == flycheck.id() && !flycheck.cannot_run_workspace() {
471471
workspace_check_triggered = true;
472472
flycheck.restart_workspace(saved_file.clone());
473473
continue 'flychecks;

0 commit comments

Comments
 (0)