Skip to content

Commit 162eced

Browse files
committed
Auto merge of rust-lang#17548 - Veykril:debug-fix, r=Veykril
fix: Fix passing `message-format` after -- in debugging Fixes rust-lang/rust-analyzer#17495 (comment)
2 parents 98238b5 + 2898181 commit 162eced

File tree

5 files changed

+15
-11
lines changed

5 files changed

+15
-11
lines changed

src/tools/rust-analyzer/editors/code/src/config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export type RunnableEnvCfgItem = {
1010
env: Record<string, string>;
1111
platform?: string | string[];
1212
};
13-
export type RunnableEnvCfg = undefined | Record<string, string> | RunnableEnvCfgItem[];
13+
export type RunnableEnvCfg = Record<string, string> | RunnableEnvCfgItem[];
1414

1515
export class Config {
1616
readonly extensionId = "rust-lang.rust-analyzer";

src/tools/rust-analyzer/editors/code/src/debug.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type * as ra from "./lsp_ext";
55

66
import { Cargo, getRustcId, getSysroot } from "./toolchain";
77
import type { Ctx } from "./ctx";
8-
import { createCargoArgs, prepareEnv } from "./run";
8+
import { prepareEnv } from "./run";
99
import { isCargoRunnableArgs, unwrapUndefinable } from "./util";
1010

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

186185
// if we are here, there were no compilation errors.
187186
return executable;

src/tools/rust-analyzer/editors/code/src/run.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export function prepareBaseEnv(base?: Record<string, string>): Record<string, st
7878
export function prepareEnv(
7979
label: string,
8080
runnableArgs: ra.CargoRunnableArgs,
81-
runnableEnvCfg: RunnableEnvCfg,
81+
runnableEnvCfg?: RunnableEnvCfg,
8282
): Record<string, string> {
8383
const env = prepareBaseEnv(runnableArgs.environment);
8484
const platform = process.platform;

src/tools/rust-analyzer/editors/code/src/toolchain.ts

+10-5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as path from "path";
44
import * as readline from "readline";
55
import * as vscode from "vscode";
66
import { execute, log, memoizeAsync, unwrapNullable, unwrapUndefinable } from "./util";
7+
import type { CargoRunnableArgs } from "./lsp_ext";
78

89
interface CompilationArtifact {
910
fileName: string;
@@ -25,9 +26,8 @@ export class Cargo {
2526
) {}
2627

2728
// Made public for testing purposes
28-
static artifactSpec(args: readonly string[]): ArtifactSpec {
29-
const cargoArgs = [...args, "--message-format=json"];
30-
29+
static artifactSpec(cargoArgs: string[], executableArgs?: string[]): ArtifactSpec {
30+
cargoArgs = [...cargoArgs, "--message-format=json"];
3131
// arguments for a runnable from the quick pick should be updated.
3232
// see crates\rust-analyzer\src\main_loop\handlers.rs, handle_code_lens
3333
switch (cargoArgs[0]) {
@@ -48,6 +48,9 @@ export class Cargo {
4848
// produce 2 artifacts: {"kind": "bin"} and {"kind": "test"}
4949
result.filter = (artifacts) => artifacts.filter((it) => it.isTest);
5050
}
51+
if (executableArgs) {
52+
cargoArgs.push("--", ...executableArgs);
53+
}
5154

5255
return result;
5356
}
@@ -84,8 +87,10 @@ export class Cargo {
8487
return spec.filter?.(artifacts) ?? artifacts;
8588
}
8689

87-
async executableFromArgs(args: readonly string[]): Promise<string> {
88-
const artifacts = await this.getArtifacts(Cargo.artifactSpec(args));
90+
async executableFromArgs(runnableArgs: CargoRunnableArgs): Promise<string> {
91+
const artifacts = await this.getArtifacts(
92+
Cargo.artifactSpec(runnableArgs.cargoArgs, runnableArgs.executableArgs),
93+
);
8994

9095
if (artifacts.length === 0) {
9196
throw new Error("No compilation artifacts");

src/tools/rust-analyzer/editors/code/tests/unit/runnable_env.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function makeRunnable(label: string): ra.Runnable {
1616
};
1717
}
1818

19-
function fakePrepareEnv(runnableName: string, config: RunnableEnvCfg): Record<string, string> {
19+
function fakePrepareEnv(runnableName: string, config?: RunnableEnvCfg): Record<string, string> {
2020
const runnable = makeRunnable(runnableName);
2121
const runnableArgs = runnable.args as ra.CargoRunnableArgs;
2222
return prepareEnv(runnable.label, runnableArgs, config);

0 commit comments

Comments
 (0)