Skip to content

Commit 8d8cc93

Browse files
committed
flycheck: Always flycheck single crate if there is a build label from rust-project.json
This requires us to add $saved_file / {saved_file} interpolation back to restart_for_package. Otherwise we break existing users of $saved_file. No grand reason why we can't delete saved_file later, although I would just leave it because sometimes a build system might really know better which target(s) to build, including multiple targets.
1 parent 210aff3 commit 8d8cc93

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

crates/rust-analyzer/src/flycheck.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,13 +219,14 @@ impl FlycheckHandle {
219219
package: PackageSpecifier,
220220
target: Option<Target>,
221221
workspace_deps: Option<FxHashSet<PackageSpecifier>>,
222+
saved_file: Option<AbsPathBuf>,
222223
) {
223224
let generation = self.generation.fetch_add(1, Ordering::Relaxed) + 1;
224225
self.sender
225226
.send(StateChange::Restart {
226227
generation,
227228
scope: FlycheckScope::Package { package, workspace_deps },
228-
saved_file: None,
229+
saved_file,
229230
target,
230231
})
231232
.unwrap();

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ fn run_flycheck(state: &mut GlobalState, vfs_path: VfsPath) -> bool {
328328
}
329329
InvocationStrategy::PerWorkspace => {
330330
Box::new(move || {
331+
let saved_file = vfs_path.as_path().map(ToOwned::to_owned);
331332
let target = TargetSpec::for_file(&world, file_id)?.map(|it| {
332333
let tgt_kind = it.target_kind();
333334
let (tgt_name, root, package) = match it {
@@ -362,8 +363,10 @@ fn run_flycheck(state: &mut GlobalState, vfs_path: VfsPath) -> bool {
362363
if let Some((target, root, package)) = target {
363364
// trigger a package check if we have a non-library target as that can't affect
364365
// anything else in the workspace OR if we're not allowed to check the workspace as
365-
// the user opted into package checks then
366-
let package_check_allowed = target.is_some() || !may_flycheck_workspace;
366+
// the user opted into package checks then OR if this is not cargo.
367+
let package_check_allowed = target.is_some()
368+
|| !may_flycheck_workspace
369+
|| matches!(package, PackageSpecifier::BuildInfo { .. });
367370
if package_check_allowed {
368371
package_workspace_idx =
369372
world.workspaces.iter().position(|ws| match &ws.kind {
@@ -390,6 +393,7 @@ fn run_flycheck(state: &mut GlobalState, vfs_path: VfsPath) -> bool {
390393
package,
391394
target,
392395
workspace_deps,
396+
saved_file.clone(),
393397
);
394398
}
395399
}
@@ -460,7 +464,6 @@ fn run_flycheck(state: &mut GlobalState, vfs_path: VfsPath) -> bool {
460464
ws_contains_file && !is_pkg_ws
461465
});
462466

463-
let saved_file = vfs_path.as_path().map(ToOwned::to_owned);
464467
let mut workspace_check_triggered = false;
465468
// Find and trigger corresponding flychecks
466469
'flychecks: for flycheck in world.flycheck.iter() {

0 commit comments

Comments
 (0)