Skip to content

Commit

Permalink
Fix passing message-format after -- in debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
Veykril committed Jul 6, 2024
1 parent 8f69d98 commit 3c9e5b8
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
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 { CargoRunnableArgs } from "./lsp_ext";

Check failure on line 7 in editors/code/src/toolchain.ts

View workflow job for this annotation

GitHub Actions / TypeScript (ubuntu-latest)

All imports in the declaration are only used as types. Use `import type`

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

0 comments on commit 3c9e5b8

Please sign in to comment.