mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-14 00:47:18 +00:00
Add cwd to CargoRunnable
This commit is contained in:
parent
f6fc109fcb
commit
c43d59c709
3 changed files with 14 additions and 0 deletions
|
@ -860,6 +860,11 @@ pub(crate) fn handle_runnables(
|
|||
if cmd == "run" && spec.target_kind != TargetKind::Bin {
|
||||
continue;
|
||||
}
|
||||
let cwd = if cmd != "test" || spec.target_kind == TargetKind::Bin {
|
||||
spec.workspace_root.clone()
|
||||
} else {
|
||||
spec.cargo_toml.parent().to_path_buf()
|
||||
};
|
||||
let mut cargo_args =
|
||||
vec![cmd.to_owned(), "--package".to_owned(), spec.package.clone()];
|
||||
let all_targets = cmd != "run" && !is_crate_no_std;
|
||||
|
@ -876,6 +881,7 @@ pub(crate) fn handle_runnables(
|
|||
kind: lsp_ext::RunnableKind::Cargo,
|
||||
args: lsp_ext::CargoRunnable {
|
||||
workspace_root: Some(spec.workspace_root.clone().into()),
|
||||
cwd: Some(cwd.into()),
|
||||
override_cargo: config.override_cargo.clone(),
|
||||
cargo_args,
|
||||
cargo_extra_args: config.cargo_extra_args.clone(),
|
||||
|
@ -893,6 +899,7 @@ pub(crate) fn handle_runnables(
|
|||
kind: lsp_ext::RunnableKind::Cargo,
|
||||
args: lsp_ext::CargoRunnable {
|
||||
workspace_root: None,
|
||||
cwd: None,
|
||||
override_cargo: config.override_cargo,
|
||||
cargo_args: vec!["check".to_owned(), "--workspace".to_owned()],
|
||||
cargo_extra_args: config.cargo_extra_args,
|
||||
|
|
|
@ -441,6 +441,8 @@ pub struct CargoRunnable {
|
|||
pub override_cargo: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub workspace_root: Option<PathBuf>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub cwd: Option<PathBuf>,
|
||||
// command, --package and --lib stuff
|
||||
pub cargo_args: Vec<String>,
|
||||
// user-specified additional cargo args, like `--release`.
|
||||
|
|
|
@ -1360,6 +1360,10 @@ pub(crate) fn runnable(
|
|||
let config = snap.config.runnables();
|
||||
let spec = CargoTargetSpec::for_file(snap, runnable.nav.file_id)?;
|
||||
let workspace_root = spec.as_ref().map(|it| it.workspace_root.clone());
|
||||
let cwd = match runnable.kind {
|
||||
ide::RunnableKind::Bin { .. } => workspace_root.clone().map(|it| it.into()),
|
||||
_ => spec.as_ref().map(|it| it.cargo_toml.parent().into()),
|
||||
};
|
||||
let target = spec.as_ref().map(|s| s.target.clone());
|
||||
let (cargo_args, executable_args) =
|
||||
CargoTargetSpec::runnable_args(snap, spec, &runnable.kind, &runnable.cfg);
|
||||
|
@ -1372,6 +1376,7 @@ pub(crate) fn runnable(
|
|||
kind: lsp_ext::RunnableKind::Cargo,
|
||||
args: lsp_ext::CargoRunnable {
|
||||
workspace_root: workspace_root.map(|it| it.into()),
|
||||
cwd,
|
||||
override_cargo: config.override_cargo,
|
||||
cargo_args,
|
||||
cargo_extra_args: config.cargo_extra_args,
|
||||
|
|
Loading…
Reference in a new issue