Skip to content

fix: Fix passing message-format after -- in debugging #17548

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion editors/code/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export type RunnableEnvCfgItem = {
env: Record<string, string>;
platform?: string | string[];
};
export type RunnableEnvCfg = undefined | Record<string, string> | RunnableEnvCfgItem[];
export type RunnableEnvCfg = Record<string, string> | RunnableEnvCfgItem[];

export class Config {
readonly extensionId = "rust-lang.rust-analyzer";
Expand Down
5 changes: 2 additions & 3 deletions editors/code/src/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type * as ra from "./lsp_ext";

import { Cargo, getRustcId, getSysroot } from "./toolchain";
import type { Ctx } from "./ctx";
import { createCargoArgs, prepareEnv } from "./run";
import { prepareEnv } from "./run";
import { isCargoRunnableArgs, unwrapUndefinable } from "./util";

const debugOutput = vscode.window.createOutputChannel("Debug");
Expand Down Expand Up @@ -180,8 +180,7 @@ async function getDebugExecutable(
env: Record<string, string>,
): Promise<string> {
const cargo = new Cargo(runnableArgs.workspaceRoot || ".", debugOutput, env);
const args = createCargoArgs(runnableArgs);
const executable = await cargo.executableFromArgs(args);
const executable = await cargo.executableFromArgs(runnableArgs);

// if we are here, there were no compilation errors.
return executable;
Expand Down
2 changes: 1 addition & 1 deletion editors/code/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export function prepareBaseEnv(base?: Record<string, string>): Record<string, st
export function prepareEnv(
label: string,
runnableArgs: ra.CargoRunnableArgs,
runnableEnvCfg: RunnableEnvCfg,
runnableEnvCfg?: RunnableEnvCfg,
): Record<string, string> {
const env = prepareBaseEnv(runnableArgs.environment);
const platform = process.platform;
Expand Down
15 changes: 10 additions & 5 deletions editors/code/src/toolchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as path from "path";
import * as readline from "readline";
import * as vscode from "vscode";
import { execute, log, memoizeAsync, unwrapNullable, unwrapUndefinable } from "./util";
import type { CargoRunnableArgs } from "./lsp_ext";

interface CompilationArtifact {
fileName: string;
Expand All @@ -25,9 +26,8 @@ export class Cargo {
) {}

// Made public for testing purposes
static artifactSpec(args: readonly string[]): ArtifactSpec {
const cargoArgs = [...args, "--message-format=json"];

static artifactSpec(cargoArgs: string[], executableArgs?: string[]): ArtifactSpec {
cargoArgs = [...cargoArgs, "--message-format=json"];
// arguments for a runnable from the quick pick should be updated.
// see crates\rust-analyzer\src\main_loop\handlers.rs, handle_code_lens
switch (cargoArgs[0]) {
Expand All @@ -48,6 +48,9 @@ export class Cargo {
// produce 2 artifacts: {"kind": "bin"} and {"kind": "test"}
result.filter = (artifacts) => artifacts.filter((it) => it.isTest);
}
if (executableArgs) {
cargoArgs.push("--", ...executableArgs);
}

return result;
}
Expand Down Expand Up @@ -84,8 +87,10 @@ export class Cargo {
return spec.filter?.(artifacts) ?? artifacts;
}

async executableFromArgs(args: readonly string[]): Promise<string> {
const artifacts = await this.getArtifacts(Cargo.artifactSpec(args));
async executableFromArgs(runnableArgs: CargoRunnableArgs): Promise<string> {
const artifacts = await this.getArtifacts(
Cargo.artifactSpec(runnableArgs.cargoArgs, runnableArgs.executableArgs),
);

if (artifacts.length === 0) {
throw new Error("No compilation artifacts");
Expand Down
2 changes: 1 addition & 1 deletion editors/code/tests/unit/runnable_env.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function makeRunnable(label: string): ra.Runnable {
};
}

function fakePrepareEnv(runnableName: string, config: RunnableEnvCfg): Record<string, string> {
function fakePrepareEnv(runnableName: string, config?: RunnableEnvCfg): Record<string, string> {
const runnable = makeRunnable(runnableName);
const runnableArgs = runnable.args as ra.CargoRunnableArgs;
return prepareEnv(runnable.label, runnableArgs, config);
Expand Down