diff options
Diffstat (limited to 'editors/code/src/debug.ts')
-rw-r--r-- | editors/code/src/debug.ts | 129 |
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'; | |||
3 | import * as path from 'path'; | 3 | import * as path from 'path'; |
4 | import * as ra from './lsp_ext'; | 4 | import * as ra from './lsp_ext'; |
5 | 5 | ||
6 | import { Cargo } from './cargo'; | 6 | import { Cargo } from './toolchain'; |
7 | import { Ctx } from "./ctx"; | 7 | import { Ctx } from "./ctx"; |
8 | import { prepareEnv } from "./run"; | ||
8 | 9 | ||
9 | const debugOutput = vscode.window.createOutputChannel("Debug"); | 10 | const debugOutput = vscode.window.createOutputChannel("Debug"); |
10 | type DebugConfigProvider = (config: ra.Runnable, executable: string, sourceFileMap?: Record<string, string>) => vscode.DebugConfiguration; | 11 | type DebugConfigProvider = (config: ra.Runnable, executable: string, env: Record<string, string>, sourceFileMap?: Record<string, string>) => vscode.DebugConfiguration; |
11 | 12 | ||
12 | function getLldbDebugConfig(config: ra.Runnable, executable: string, sourceFileMap?: Record<string, string>): vscode.DebugConfiguration { | 13 | export 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 | ||
25 | function 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 | ||
37 | async function getDebugExecutable(config: ra.Runnable): Promise<string> { | 36 | export 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 | ||
45 | export async function getDebugConfiguration(ctx: Ctx, config: ra.Runnable): Promise<vscode.DebugConfiguration | undefined> { | 59 | async 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 | ||
103 | export async function startDebugSession(ctx: Ctx, config: ra.Runnable): Promise<boolean> { | 118 | async 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; | 126 | function 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}:`); | 140 | function 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 | } |