Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'editors/code/src/debug.ts')
| -rw-r--r-- | editors/code/src/debug.ts | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/editors/code/src/debug.ts b/editors/code/src/debug.ts index 4b96e4d5c8..eef2f6f4ee 100644 --- a/editors/code/src/debug.ts +++ b/editors/code/src/debug.ts @@ -7,10 +7,12 @@ import { Cargo, getRustcId, getSysroot } from "./toolchain"; import type { Ctx } from "./ctx"; import { prepareEnv } from "./run"; import { unwrapUndefinable } from "./undefinable"; +import { isCargoRunnableArgs } from "./util"; const debugOutput = vscode.window.createOutputChannel("Debug"); type DebugConfigProvider = ( - config: ra.Runnable, + runnable: ra.Runnable, + runnableArgs: ra.CargoRunnableArgs, executable: string, env: Record<string, string>, sourceFileMap?: Record<string, string>, @@ -76,6 +78,11 @@ async function getDebugConfiguration( ctx: Ctx, runnable: ra.Runnable, ): Promise<vscode.DebugConfiguration | undefined> { + if (!isCargoRunnableArgs(runnable.args)) { + return; + } + const runnableArgs: ra.CargoRunnableArgs = runnable.args; + const editor = ctx.activeRustEditor; if (!editor) return; @@ -119,9 +126,9 @@ async function getDebugConfiguration( const isMultiFolderWorkspace = workspaceFolders.length > 1; const firstWorkspace = workspaceFolders[0]; const maybeWorkspace = - !isMultiFolderWorkspace || !runnable.args.workspaceRoot + !isMultiFolderWorkspace || !runnableArgs.workspaceRoot ? firstWorkspace - : workspaceFolders.find((w) => runnable.args.workspaceRoot?.includes(w.uri.fsPath)) || + : workspaceFolders.find((w) => runnableArgs.workspaceRoot?.includes(w.uri.fsPath)) || firstWorkspace; const workspace = unwrapUndefinable(maybeWorkspace); @@ -132,8 +139,8 @@ async function getDebugConfiguration( return path.normalize(p).replace(wsFolder, "${workspaceFolder" + workspaceQualifier + "}"); } - const env = prepareEnv(runnable, ctx.config.runnablesExtraEnv); - const executable = await getDebugExecutable(runnable, env); + const env = prepareEnv(runnable.label, runnableArgs, ctx.config.runnablesExtraEnv); + const executable = await getDebugExecutable(runnableArgs, env); let sourceFileMap = debugOptions.sourceFileMap; if (sourceFileMap === "auto") { // let's try to use the default toolchain @@ -147,7 +154,7 @@ async function getDebugConfiguration( } const provider = unwrapUndefinable(knownEngines[debugEngine.id]); - const debugConfig = provider(runnable, simplifyPath(executable), env, sourceFileMap); + const debugConfig = provider(runnable, runnableArgs, simplifyPath(executable), env); if (debugConfig.type in debugOptions.engineSettings) { const settingsMap = (debugOptions.engineSettings as any)[debugConfig.type]; for (var key in settingsMap) { @@ -170,11 +177,11 @@ async function getDebugConfiguration( } async function getDebugExecutable( - runnable: ra.Runnable, + runnableArgs: ra.CargoRunnableArgs, env: Record<string, string>, ): Promise<string> { - const cargo = new Cargo(runnable.args.workspaceRoot || ".", debugOutput, env); - const executable = await cargo.executableFromArgs(runnable.args.cargoArgs); + const cargo = new Cargo(runnableArgs.workspaceRoot || ".", debugOutput, env); + const executable = await cargo.executableFromArgs(runnableArgs.cargoArgs); // if we are here, there were no compilation errors. return executable; @@ -182,6 +189,7 @@ async function getDebugExecutable( function getCCppDebugConfig( runnable: ra.Runnable, + runnableArgs: ra.CargoRunnableArgs, executable: string, env: Record<string, string>, sourceFileMap?: Record<string, string>, @@ -191,8 +199,8 @@ function getCCppDebugConfig( request: "launch", name: runnable.label, program: executable, - args: runnable.args.executableArgs, - cwd: runnable.args.cwd || runnable.args.workspaceRoot || ".", + args: runnableArgs.executableArgs, + cwd: runnable.args.cwd || runnableArgs.workspaceRoot || ".", sourceFileMap, environment: Object.entries(env).map((entry) => ({ name: entry[0], @@ -207,6 +215,7 @@ function getCCppDebugConfig( function getCodeLldbDebugConfig( runnable: ra.Runnable, + runnableArgs: ra.CargoRunnableArgs, executable: string, env: Record<string, string>, sourceFileMap?: Record<string, string>, @@ -216,8 +225,8 @@ function getCodeLldbDebugConfig( request: "launch", name: runnable.label, program: executable, - args: runnable.args.executableArgs, - cwd: runnable.args.cwd || runnable.args.workspaceRoot || ".", + args: runnableArgs.executableArgs, + cwd: runnable.args.cwd || runnableArgs.workspaceRoot || ".", sourceMap: sourceFileMap, sourceLanguages: ["rust"], env, @@ -226,6 +235,7 @@ function getCodeLldbDebugConfig( function getNativeDebugConfig( runnable: ra.Runnable, + runnableArgs: ra.CargoRunnableArgs, executable: string, env: Record<string, string>, _sourceFileMap?: Record<string, string>, @@ -236,8 +246,8 @@ function getNativeDebugConfig( name: runnable.label, target: executable, // See https://github.com/WebFreak001/code-debug/issues/359 - arguments: quote(runnable.args.executableArgs), - cwd: runnable.args.cwd || runnable.args.workspaceRoot || ".", + arguments: quote(runnableArgs.executableArgs), + cwd: runnable.args.cwd || runnableArgs.workspaceRoot || ".", env, valuesFormatting: "prettyPrinters", }; |