Unnamed repository; edit this file 'description' to name the repository.
Fix passing message-format after -- in debugging
Lukas Wirth 2024-07-06
parent 8f69d98 · commit 7733403
-rw-r--r--editors/code/src/config.ts2
-rw-r--r--editors/code/src/debug.ts5
-rw-r--r--editors/code/src/run.ts2
-rw-r--r--editors/code/src/toolchain.ts15
-rw-r--r--editors/code/tests/unit/runnable_env.test.ts2
5 files changed, 15 insertions, 11 deletions
diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts
index 1931cfe381..527fad944f 100644
--- a/editors/code/src/config.ts
+++ b/editors/code/src/config.ts
@@ -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";
diff --git a/editors/code/src/debug.ts b/editors/code/src/debug.ts
index c2da2ea4e3..f23e368093 100644
--- a/editors/code/src/debug.ts
+++ b/editors/code/src/debug.ts
@@ -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");
@@ -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;
diff --git a/editors/code/src/run.ts b/editors/code/src/run.ts
index 849e915cca..583f803d9a 100644
--- a/editors/code/src/run.ts
+++ b/editors/code/src/run.ts
@@ -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;
diff --git a/editors/code/src/toolchain.ts b/editors/code/src/toolchain.ts
index a48d2d90cc..6a0b5c26d8 100644
--- a/editors/code/src/toolchain.ts
+++ b/editors/code/src/toolchain.ts
@@ -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;
@@ -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]) {
@@ -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;
}
@@ -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");
diff --git a/editors/code/tests/unit/runnable_env.test.ts b/editors/code/tests/unit/runnable_env.test.ts
index 1551393821..81850e03f1 100644
--- a/editors/code/tests/unit/runnable_env.test.ts
+++ b/editors/code/tests/unit/runnable_env.test.ts
@@ -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);