Skip to content

VSCode: Debug run does not respect rust-analyzer.runnables.extraArgs #17128

Closed
@schurwanzn-stabl

Description

@schurwanzn-stabl

rust-analyzer version: 0.3.1932-standalone
rustc version: rustc 1.79.0-nightly (7f2fc33da 2024-04-22)

editor or extension: VSCode - rust-analyzer v0.3.1932

relevant settings: rust-analyzer.cargo.target

repository link (if public, optional): Minimal reproducible example (needs nightly toolchain, but that's not relevant to the issue itself)

code snippet to reproduce: Code snippet does not suffice to reproduce, see linked repository

The MRE (minimal reproducible example) enables -Z build-std via it's .cargo/cargo.toml. The build-std feature requires that any cargo build/test/run/... command be called with the --target=... option - compilation fails without it. This makes it ideal to showcase the issue.
The --target x86_64-unknown-linux-gnu option is set by rust-analyzer.runnables.extraArgs. Using, for example, code lens to Run the test or the main function of the MRE will work as expected (try it without the rust-analyzer.runnables.extraArgs setting - it will fail).
However, running the Debug code lens will fail with error: -Zbuild-std requires --target.


Comparing the relevant code for debug running

async function getDebugExecutableInfo(
runnable: ra.Runnable,
env: Record<string, string>,
): Promise<ExecutableInfo> {
const cargo = new Cargo(runnable.args.workspaceRoot || ".", debugOutput, env);
const executableInfo = await cargo.executableInfoFromArgs(runnable.args.cargoArgs);
// if we are here, there were no compilation errors.
return executableInfo;
}

with the equivalent code for non-debug running
export function createArgs(runnable: ra.Runnable): string[] {
const args = [...runnable.args.cargoArgs]; // should be a copy!
if (runnable.args.cargoExtraArgs) {
args.push(...runnable.args.cargoExtraArgs); // Append user-specified cargo options.
}
if (runnable.args.executableArgs.length > 0) {
args.push("--", ...runnable.args.executableArgs);
}
return args;
}

seems to confirm that rust-analyzer.runnables.extraArgs is ignored on debug runs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-vscodevscode plugin issuesC-bugCategory: bugE-has-instructionsIssue has some instructions and pointers to code to get started

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions