Auto merge of #17548 - Veykril:debug-fix, r=Veykril

fix: Fix passing `message-format` after -- in debugging

Fixes https://github.com/rust-lang/rust-analyzer/pull/17495#issuecomment-2211717224
This commit is contained in:
bors 2024-07-06 16:04:53 +00:00
commit c888c0f109
5 changed files with 15 additions and 11 deletions

View file

@ -10,7 +10,7 @@ export type RunnableEnvCfgItem = {
env: Record<string, string>; env: Record<string, string>;
platform?: string | string[]; platform?: string | string[];
}; };
export type RunnableEnvCfg = undefined | Record<string, string> | RunnableEnvCfgItem[]; export type RunnableEnvCfg = Record<string, string> | RunnableEnvCfgItem[];
export class Config { export class Config {
readonly extensionId = "rust-lang.rust-analyzer"; readonly extensionId = "rust-lang.rust-analyzer";

View file

@ -5,7 +5,7 @@ import type * as ra from "./lsp_ext";
import { Cargo, getRustcId, getSysroot } from "./toolchain"; import { Cargo, getRustcId, getSysroot } from "./toolchain";
import type { Ctx } from "./ctx"; import type { Ctx } from "./ctx";
import { createCargoArgs, prepareEnv } from "./run"; import { prepareEnv } from "./run";
import { isCargoRunnableArgs, unwrapUndefinable } from "./util"; import { isCargoRunnableArgs, unwrapUndefinable } from "./util";
const debugOutput = vscode.window.createOutputChannel("Debug"); const debugOutput = vscode.window.createOutputChannel("Debug");
@ -180,8 +180,7 @@ async function getDebugExecutable(
env: Record<string, string>, env: Record<string, string>,
): Promise<string> { ): Promise<string> {
const cargo = new Cargo(runnableArgs.workspaceRoot || ".", debugOutput, env); const cargo = new Cargo(runnableArgs.workspaceRoot || ".", debugOutput, env);
const args = createCargoArgs(runnableArgs); const executable = await cargo.executableFromArgs(runnableArgs);
const executable = await cargo.executableFromArgs(args);
// if we are here, there were no compilation errors. // if we are here, there were no compilation errors.
return executable; return executable;

View file

@ -78,7 +78,7 @@ export function prepareBaseEnv(base?: Record<string, string>): Record<string, st
export function prepareEnv( export function prepareEnv(
label: string, label: string,
runnableArgs: ra.CargoRunnableArgs, runnableArgs: ra.CargoRunnableArgs,
runnableEnvCfg: RunnableEnvCfg, runnableEnvCfg?: RunnableEnvCfg,
): Record<string, string> { ): Record<string, string> {
const env = prepareBaseEnv(runnableArgs.environment); const env = prepareBaseEnv(runnableArgs.environment);
const platform = process.platform; const platform = process.platform;

View file

@ -4,6 +4,7 @@ import * as path from "path";
import * as readline from "readline"; import * as readline from "readline";
import * as vscode from "vscode"; import * as vscode from "vscode";
import { execute, log, memoizeAsync, unwrapNullable, unwrapUndefinable } from "./util"; import { execute, log, memoizeAsync, unwrapNullable, unwrapUndefinable } from "./util";
import type { CargoRunnableArgs } from "./lsp_ext";
interface CompilationArtifact { interface CompilationArtifact {
fileName: string; fileName: string;
@ -25,9 +26,8 @@ export class Cargo {
) {} ) {}
// Made public for testing purposes // Made public for testing purposes
static artifactSpec(args: readonly string[]): ArtifactSpec { static artifactSpec(cargoArgs: string[], executableArgs?: string[]): ArtifactSpec {
const cargoArgs = [...args, "--message-format=json"]; cargoArgs = [...cargoArgs, "--message-format=json"];
// arguments for a runnable from the quick pick should be updated. // arguments for a runnable from the quick pick should be updated.
// see crates\rust-analyzer\src\main_loop\handlers.rs, handle_code_lens // see crates\rust-analyzer\src\main_loop\handlers.rs, handle_code_lens
switch (cargoArgs[0]) { switch (cargoArgs[0]) {
@ -48,6 +48,9 @@ export class Cargo {
// produce 2 artifacts: {"kind": "bin"} and {"kind": "test"} // produce 2 artifacts: {"kind": "bin"} and {"kind": "test"}
result.filter = (artifacts) => artifacts.filter((it) => it.isTest); result.filter = (artifacts) => artifacts.filter((it) => it.isTest);
} }
if (executableArgs) {
cargoArgs.push("--", ...executableArgs);
}
return result; return result;
} }
@ -84,8 +87,10 @@ export class Cargo {
return spec.filter?.(artifacts) ?? artifacts; return spec.filter?.(artifacts) ?? artifacts;
} }
async executableFromArgs(args: readonly string[]): Promise<string> { async executableFromArgs(runnableArgs: CargoRunnableArgs): Promise<string> {
const artifacts = await this.getArtifacts(Cargo.artifactSpec(args)); const artifacts = await this.getArtifacts(
Cargo.artifactSpec(runnableArgs.cargoArgs, runnableArgs.executableArgs),
);
if (artifacts.length === 0) { if (artifacts.length === 0) {
throw new Error("No compilation artifacts"); throw new Error("No compilation artifacts");

View file

@ -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 runnable = makeRunnable(runnableName);
const runnableArgs = runnable.args as ra.CargoRunnableArgs; const runnableArgs = runnable.args as ra.CargoRunnableArgs;
return prepareEnv(runnable.label, runnableArgs, config); return prepareEnv(runnable.label, runnableArgs, config);