Skip to content

Commit

Permalink
Don't emit current dir as cwd for runnables
Browse files Browse the repository at this point in the history
  • Loading branch information
Veykril committed Jul 6, 2024
1 parent 3d7ee9b commit ae642ea
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
32 changes: 17 additions & 15 deletions crates/rust-analyzer/src/handlers/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -897,21 +897,23 @@ pub(crate) fn handle_runnables(
Some(TargetSpec::ProjectJson(_)) => {}
None => {
if !snap.config.linked_or_discovered_projects().is_empty() {
let mut cargo_args = vec!["check".to_owned(), "--workspace".to_owned()];
cargo_args.extend(config.cargo_extra_args.iter().cloned());
res.push(lsp_ext::Runnable {
label: "cargo check --workspace".to_owned(),
location: None,
kind: lsp_ext::RunnableKind::Cargo,
args: lsp_ext::RunnableArgs::Cargo(lsp_ext::CargoRunnableArgs {
workspace_root: None,
cwd: ".".into(),
override_cargo: config.override_cargo,
cargo_args,
executable_args: Vec::new(),
environment: Default::default(),
}),
});
if let Some(path) = snap.file_id_to_file_path(file_id).parent() {
let mut cargo_args = vec!["check".to_owned(), "--workspace".to_owned()];
cargo_args.extend(config.cargo_extra_args.iter().cloned());
res.push(lsp_ext::Runnable {
label: "cargo check --workspace".to_owned(),
location: None,
kind: lsp_ext::RunnableKind::Cargo,
args: lsp_ext::RunnableArgs::Cargo(lsp_ext::CargoRunnableArgs {
workspace_root: None,
cwd: path.as_path().unwrap().to_path_buf().into(),
override_cargo: config.override_cargo,
cargo_args,
executable_args: Vec::new(),
environment: Default::default(),
}),
});
};
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion crates/rust-analyzer/src/lsp/to_proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1419,6 +1419,9 @@ pub(crate) fn runnable(
}
}
None => {
let Some(path) = snap.file_id_to_file_path(runnable.nav.file_id).parent() else {
return Ok(None);
};
let (cargo_args, executable_args) =
CargoTargetSpec::runnable_args(snap, None, &runnable.kind, &runnable.cfg);

Expand All @@ -1433,7 +1436,7 @@ pub(crate) fn runnable(
workspace_root: None,
override_cargo: config.override_cargo,
cargo_args,
cwd: Utf8PathBuf::from("."),
cwd: path.as_path().unwrap().to_path_buf().into(),
executable_args,
environment: Default::default(),
}),
Expand Down

0 comments on commit ae642ea

Please sign in to comment.