mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +00:00
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:
commit
c888c0f109
5 changed files with 15 additions and 11 deletions
|
@ -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";
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue