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.ts43
1 files changed, 26 insertions, 17 deletions
diff --git a/editors/code/src/debug.ts b/editors/code/src/debug.ts
index 4b96e4d5c8..58fe1df51f 100644
--- a/editors/code/src/debug.ts
+++ b/editors/code/src/debug.ts
@@ -6,11 +6,12 @@ import type * as ra from "./lsp_ext";
import { Cargo, getRustcId, getSysroot } from "./toolchain";
import type { Ctx } from "./ctx";
import { prepareEnv } from "./run";
-import { unwrapUndefinable } from "./undefinable";
+import { isCargoRunnableArgs, unwrapUndefinable } 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 +77,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 +125,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);
@@ -129,11 +135,11 @@ async function getDebugConfiguration(
const workspaceQualifier = isMultiFolderWorkspace ? `:${workspace.name}` : "";
function simplifyPath(p: string): string {
// see https://github.com/rust-lang/rust-analyzer/pull/5513#issuecomment-663458818 for why this is needed
- return path.normalize(p).replace(wsFolder, "${workspaceFolder" + workspaceQualifier + "}");
+ 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 +153,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 +176,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 +188,7 @@ async function getDebugExecutable(
function getCCppDebugConfig(
runnable: ra.Runnable,
+ runnableArgs: ra.CargoRunnableArgs,
executable: string,
env: Record<string, string>,
sourceFileMap?: Record<string, string>,
@@ -191,8 +198,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 +214,7 @@ function getCCppDebugConfig(
function getCodeLldbDebugConfig(
runnable: ra.Runnable,
+ runnableArgs: ra.CargoRunnableArgs,
executable: string,
env: Record<string, string>,
sourceFileMap?: Record<string, string>,
@@ -216,8 +224,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 +234,7 @@ function getCodeLldbDebugConfig(
function getNativeDebugConfig(
runnable: ra.Runnable,
+ runnableArgs: ra.CargoRunnableArgs,
executable: string,
env: Record<string, string>,
_sourceFileMap?: Record<string, string>,
@@ -236,8 +245,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",
};