about summary refs log tree commit diff
path: root/editors/code/src/debug.ts
diff options
context:
space:
mode:
Diffstat (limited to 'editors/code/src/debug.ts')
-rw-r--r--editors/code/src/debug.ts37
1 files changed, 18 insertions, 19 deletions
diff --git a/editors/code/src/debug.ts b/editors/code/src/debug.ts
index cffee1de6af..f3d6238d51b 100644
--- a/editors/code/src/debug.ts
+++ b/editors/code/src/debug.ts
@@ -1,18 +1,19 @@
 import * as os from "os";
 import * as vscode from "vscode";
 import * as path from "path";
-import * as ra from "./lsp_ext";
+import type * as ra from "./lsp_ext";
 
 import { Cargo, getRustcId, getSysroot } from "./toolchain";
-import { Ctx } from "./ctx";
+import type { Ctx } from "./ctx";
 import { prepareEnv } from "./run";
+import { unwrapUndefinable } from "./undefinable";
 
 const debugOutput = vscode.window.createOutputChannel("Debug");
 type DebugConfigProvider = (
     config: ra.Runnable,
     executable: string,
     env: Record<string, string>,
-    sourceFileMap?: Record<string, string>
+    sourceFileMap?: Record<string, string>,
 ) => vscode.DebugConfiguration;
 
 export async function makeDebugConfig(ctx: Ctx, runnable: ra.Runnable): Promise<void> {
@@ -30,7 +31,7 @@ export async function makeDebugConfig(ctx: Ctx, runnable: ra.Runnable): Promise<
         const answer = await vscode.window.showErrorMessage(
             `Launch configuration '${debugConfig.name}' already exists!`,
             "Cancel",
-            "Update"
+            "Update",
         );
         if (answer === "Cancel") return;
 
@@ -67,7 +68,7 @@ export async function startDebugSession(ctx: Ctx, runnable: ra.Runnable): Promis
 
 async function getDebugConfiguration(
     ctx: Ctx,
-    runnable: ra.Runnable
+    runnable: ra.Runnable,
 ): Promise<vscode.DebugConfiguration | undefined> {
     const editor = ctx.activeRustEditor;
     if (!editor) return;
@@ -91,7 +92,7 @@ async function getDebugConfiguration(
     if (!debugEngine) {
         await vscode.window.showErrorMessage(
             `Install [CodeLLDB](https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb)` +
-                ` or [MS C++ tools](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools) extension for debugging.`
+                ` or [MS C++ tools](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools) extension for debugging.`,
         );
         return;
     }
@@ -105,12 +106,13 @@ async function getDebugConfiguration(
     const workspaceFolders = vscode.workspace.workspaceFolders!;
     const isMultiFolderWorkspace = workspaceFolders.length > 1;
     const firstWorkspace = workspaceFolders[0];
-    const workspace =
+    const maybeWorkspace =
         !isMultiFolderWorkspace || !runnable.args.workspaceRoot
             ? firstWorkspace
             : workspaceFolders.find((w) => runnable.args.workspaceRoot?.includes(w.uri.fsPath)) ||
               firstWorkspace;
 
+    const workspace = unwrapUndefinable(maybeWorkspace);
     const wsFolder = path.normalize(workspace.uri.fsPath);
     const workspaceQualifier = isMultiFolderWorkspace ? `:${workspace.name}` : "";
     function simplifyPath(p: string): string {
@@ -118,7 +120,7 @@ async function getDebugConfiguration(
         return path.normalize(p).replace(wsFolder, "${workspaceFolder" + workspaceQualifier + "}");
     }
 
-    const env = prepareEnv(runnable, ctx.config.runnableEnv);
+    const env = prepareEnv(runnable, ctx.config.runnablesExtraEnv);
     const executable = await getDebugExecutable(runnable, env);
     let sourceFileMap = debugOptions.sourceFileMap;
     if (sourceFileMap === "auto") {
@@ -130,12 +132,8 @@ async function getDebugConfiguration(
         sourceFileMap[`/rustc/${commitHash}/`] = rustlib;
     }
 
-    const debugConfig = knownEngines[debugEngine.id](
-        runnable,
-        simplifyPath(executable),
-        env,
-        sourceFileMap
-    );
+    const provider = unwrapUndefinable(knownEngines[debugEngine.id]);
+    const debugConfig = provider(runnable, simplifyPath(executable), env, sourceFileMap);
     if (debugConfig.type in debugOptions.engineSettings) {
         const settingsMap = (debugOptions.engineSettings as any)[debugConfig.type];
         for (var key in settingsMap) {
@@ -149,8 +147,9 @@ async function getDebugConfiguration(
         debugConfig.name = `run ${path.basename(executable)}`;
     }
 
-    if (debugConfig.cwd) {
-        debugConfig.cwd = simplifyPath(debugConfig.cwd);
+    const cwd = debugConfig["cwd"];
+    if (cwd) {
+        debugConfig["cwd"] = simplifyPath(cwd);
     }
 
     return debugConfig;
@@ -158,7 +157,7 @@ async function getDebugConfiguration(
 
 async function getDebugExecutable(
     runnable: ra.Runnable,
-    env: Record<string, string>
+    env: Record<string, string>,
 ): Promise<string> {
     const cargo = new Cargo(runnable.args.workspaceRoot || ".", debugOutput, env);
     const executable = await cargo.executableFromArgs(runnable.args.cargoArgs);
@@ -171,7 +170,7 @@ function getLldbDebugConfig(
     runnable: ra.Runnable,
     executable: string,
     env: Record<string, string>,
-    sourceFileMap?: Record<string, string>
+    sourceFileMap?: Record<string, string>,
 ): vscode.DebugConfiguration {
     return {
         type: "lldb",
@@ -190,7 +189,7 @@ function getCppvsDebugConfig(
     runnable: ra.Runnable,
     executable: string,
     env: Record<string, string>,
-    sourceFileMap?: Record<string, string>
+    sourceFileMap?: Record<string, string>,
 ): vscode.DebugConfiguration {
     return {
         type: os.platform() === "win32" ? "cppvsdbg" : "cppdbg",