Skip to content

Commit ae642ea

Browse files
committed
Don't emit current dir as cwd for runnables
1 parent 3d7ee9b commit ae642ea

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

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

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -897,21 +897,23 @@ pub(crate) fn handle_runnables(
897897
Some(TargetSpec::ProjectJson(_)) => {}
898898
None => {
899899
if !snap.config.linked_or_discovered_projects().is_empty() {
900-
let mut cargo_args = vec!["check".to_owned(), "--workspace".to_owned()];
901-
cargo_args.extend(config.cargo_extra_args.iter().cloned());
902-
res.push(lsp_ext::Runnable {
903-
label: "cargo check --workspace".to_owned(),
904-
location: None,
905-
kind: lsp_ext::RunnableKind::Cargo,
906-
args: lsp_ext::RunnableArgs::Cargo(lsp_ext::CargoRunnableArgs {
907-
workspace_root: None,
908-
cwd: ".".into(),
909-
override_cargo: config.override_cargo,
910-
cargo_args,
911-
executable_args: Vec::new(),
912-
environment: Default::default(),
913-
}),
914-
});
900+
if let Some(path) = snap.file_id_to_file_path(file_id).parent() {
901+
let mut cargo_args = vec!["check".to_owned(), "--workspace".to_owned()];
902+
cargo_args.extend(config.cargo_extra_args.iter().cloned());
903+
res.push(lsp_ext::Runnable {
904+
label: "cargo check --workspace".to_owned(),
905+
location: None,
906+
kind: lsp_ext::RunnableKind::Cargo,
907+
args: lsp_ext::RunnableArgs::Cargo(lsp_ext::CargoRunnableArgs {
908+
workspace_root: None,
909+
cwd: path.as_path().unwrap().to_path_buf().into(),
910+
override_cargo: config.override_cargo,
911+
cargo_args,
912+
executable_args: Vec::new(),
913+
environment: Default::default(),
914+
}),
915+
});
916+
};
915917
}
916918
}
917919
}

crates/rust-analyzer/src/lsp/to_proto.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1419,6 +1419,9 @@ pub(crate) fn runnable(
14191419
}
14201420
}
14211421
None => {
1422+
let Some(path) = snap.file_id_to_file_path(runnable.nav.file_id).parent() else {
1423+
return Ok(None);
1424+
};
14221425
let (cargo_args, executable_args) =
14231426
CargoTargetSpec::runnable_args(snap, None, &runnable.kind, &runnable.cfg);
14241427

@@ -1433,7 +1436,7 @@ pub(crate) fn runnable(
14331436
workspace_root: None,
14341437
override_cargo: config.override_cargo,
14351438
cargo_args,
1436-
cwd: Utf8PathBuf::from("."),
1439+
cwd: path.as_path().unwrap().to_path_buf().into(),
14371440
executable_args,
14381441
environment: Default::default(),
14391442
}),

0 commit comments

Comments
 (0)