aboutsummaryrefslogtreecommitdiff
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.ts129
1 files changed, 78 insertions, 51 deletions
diff --git a/editors/code/src/debug.ts b/editors/code/src/debug.ts
index 027504ecd..bd92c5b6d 100644
--- a/editors/code/src/debug.ts
+++ b/editors/code/src/debug.ts
@@ -3,46 +3,60 @@ import * as vscode from 'vscode';
3import * as path from 'path'; 3import * as path from 'path';
4import * as ra from './lsp_ext'; 4import * as ra from './lsp_ext';
5 5
6import { Cargo } from './cargo'; 6import { Cargo } from './toolchain';
7import { Ctx } from "./ctx"; 7import { Ctx } from "./ctx";
8import { prepareEnv } from "./run";
8 9
9const debugOutput = vscode.window.createOutputChannel("Debug"); 10const debugOutput = vscode.window.createOutputChannel("Debug");
10type DebugConfigProvider = (config: ra.Runnable, executable: string, sourceFileMap?: Record<string, string>) => vscode.DebugConfiguration; 11type DebugConfigProvider = (config: ra.Runnable, executable: string, env: Record<string, string>, sourceFileMap?: Record<string, string>) => vscode.DebugConfiguration;
11 12
12function getLldbDebugConfig(config: ra.Runnable, executable: string, sourceFileMap?: Record<string, string>): vscode.DebugConfiguration { 13export async function makeDebugConfig(ctx: Ctx, runnable: ra.Runnable): Promise<void> {
13 return { 14 const scope = ctx.activeRustEditor?.document.uri;
14 type: "lldb", 15 if (!scope) return;
15 request: "launch",
16 name: config.label,
17 program: executable,
18 args: config.extraArgs,
19 cwd: config.cwd,
20 sourceMap: sourceFileMap,
21 sourceLanguages: ["rust"]
22 };
23}
24 16
25function getCppvsDebugConfig(config: ra.Runnable, executable: string, sourceFileMap?: Record<string, string>): vscode.DebugConfiguration { 17 const debugConfig = await getDebugConfiguration(ctx, runnable);
26 return { 18 if (!debugConfig) return;
27 type: (os.platform() === "win32") ? "cppvsdbg" : "cppdbg", 19
28 request: "launch", 20 const wsLaunchSection = vscode.workspace.getConfiguration("launch", scope);
29 name: config.label, 21 const configurations = wsLaunchSection.get<any[]>("configurations") || [];
30 program: executable, 22
31 args: config.extraArgs, 23 const index = configurations.findIndex(c => c.name === debugConfig.name);
32 cwd: config.cwd, 24 if (index !== -1) {
33 sourceFileMap: sourceFileMap, 25 const answer = await vscode.window.showErrorMessage(`Launch configuration '${debugConfig.name}' already exists!`, 'Cancel', 'Update');
34 }; 26 if (answer === "Cancel") return;
27
28 configurations[index] = debugConfig;
29 } else {
30 configurations.push(debugConfig);
31 }
32
33 await wsLaunchSection.update("configurations", configurations);
35} 34}
36 35
37async function getDebugExecutable(config: ra.Runnable): Promise<string> { 36export async function startDebugSession(ctx: Ctx, runnable: ra.Runnable): Promise<boolean> {
38 const cargo = new Cargo(config.cwd || '.', debugOutput); 37 let debugConfig: vscode.DebugConfiguration | undefined = undefined;
39 const executable = await cargo.executableFromArgs(config.args); 38 let message = "";
40 39
41 // if we are here, there were no compilation errors. 40 const wsLaunchSection = vscode.workspace.getConfiguration("launch");
42 return executable; 41 const configurations = wsLaunchSection.get<any[]>("configurations") || [];
42
43 const index = configurations.findIndex(c => c.name === runnable.label);
44 if (-1 !== index) {
45 debugConfig = configurations[index];
46 message = " (from launch.json)";
47 debugOutput.clear();
48 } else {
49 debugConfig = await getDebugConfiguration(ctx, runnable);
50 }
51
52 if (!debugConfig) return false;
53
54 debugOutput.appendLine(`Launching debug configuration${message}:`);
55 debugOutput.appendLine(JSON.stringify(debugConfig, null, 2));
56 return vscode.debug.startDebugging(undefined, debugConfig);
43} 57}
44 58
45export async function getDebugConfiguration(ctx: Ctx, config: ra.Runnable): Promise<vscode.DebugConfiguration | undefined> { 59async function getDebugConfiguration(ctx: Ctx, runnable: ra.Runnable): Promise<vscode.DebugConfiguration | undefined> {
46 const editor = ctx.activeRustEditor; 60 const editor = ctx.activeRustEditor;
47 if (!editor) return; 61 if (!editor) return;
48 62
@@ -69,7 +83,7 @@ export async function getDebugConfiguration(ctx: Ctx, config: ra.Runnable): Prom
69 } 83 }
70 84
71 debugOutput.clear(); 85 debugOutput.clear();
72 if (ctx.config.debug.openUpDebugPane) { 86 if (ctx.config.debug.openDebugPane) {
73 debugOutput.show(true); 87 debugOutput.show(true);
74 } 88 }
75 89
@@ -78,8 +92,9 @@ export async function getDebugConfiguration(ctx: Ctx, config: ra.Runnable): Prom
78 return path.normalize(p).replace(wsFolder, '${workspaceRoot}'); 92 return path.normalize(p).replace(wsFolder, '${workspaceRoot}');
79 } 93 }
80 94
81 const executable = await getDebugExecutable(config); 95 const executable = await getDebugExecutable(runnable);
82 const debugConfig = knownEngines[debugEngine.id](config, simplifyPath(executable), debugOptions.sourceFileMap); 96 const env = prepareEnv(runnable, ctx.config.runnableEnv);
97 const debugConfig = knownEngines[debugEngine.id](runnable, simplifyPath(executable), env, debugOptions.sourceFileMap);
83 if (debugConfig.type in debugOptions.engineSettings) { 98 if (debugConfig.type in debugOptions.engineSettings) {
84 const settingsMap = (debugOptions.engineSettings as any)[debugConfig.type]; 99 const settingsMap = (debugOptions.engineSettings as any)[debugConfig.type];
85 for (var key in settingsMap) { 100 for (var key in settingsMap) {
@@ -100,25 +115,37 @@ export async function getDebugConfiguration(ctx: Ctx, config: ra.Runnable): Prom
100 return debugConfig; 115 return debugConfig;
101} 116}
102 117
103export async function startDebugSession(ctx: Ctx, config: ra.Runnable): Promise<boolean> { 118async function getDebugExecutable(runnable: ra.Runnable): Promise<string> {
104 let debugConfig: vscode.DebugConfiguration | undefined = undefined; 119 const cargo = new Cargo(runnable.args.workspaceRoot || '.', debugOutput);
105 let message = ""; 120 const executable = await cargo.executableFromArgs(runnable.args.cargoArgs);
106
107 const wsLaunchSection = vscode.workspace.getConfiguration("launch");
108 const configurations = wsLaunchSection.get<any[]>("configurations") || [];
109 121
110 const index = configurations.findIndex(c => c.name === config.label); 122 // if we are here, there were no compilation errors.
111 if (-1 !== index) { 123 return executable;
112 debugConfig = configurations[index]; 124}
113 message = " (from launch.json)";
114 debugOutput.clear();
115 } else {
116 debugConfig = await getDebugConfiguration(ctx, config);
117 }
118 125
119 if (!debugConfig) return false; 126function getLldbDebugConfig(runnable: ra.Runnable, executable: string, env: Record<string, string>, sourceFileMap?: Record<string, string>): vscode.DebugConfiguration {
127 return {
128 type: "lldb",
129 request: "launch",
130 name: runnable.label,
131 program: executable,
132 args: runnable.args.executableArgs,
133 cwd: runnable.args.workspaceRoot,
134 sourceMap: sourceFileMap,
135 sourceLanguages: ["rust"],
136 env
137 };
138}
120 139
121 debugOutput.appendLine(`Launching debug configuration${message}:`); 140function getCppvsDebugConfig(runnable: ra.Runnable, executable: string, env: Record<string, string>, sourceFileMap?: Record<string, string>): vscode.DebugConfiguration {
122 debugOutput.appendLine(JSON.stringify(debugConfig, null, 2)); 141 return {
123 return vscode.debug.startDebugging(undefined, debugConfig); 142 type: (os.platform() === "win32") ? "cppvsdbg" : "cppdbg",
143 request: "launch",
144 name: runnable.label,
145 program: executable,
146 args: runnable.args.executableArgs,
147 cwd: runnable.args.workspaceRoot,
148 sourceFileMap,
149 env,
150 };
124} 151}