diff options
| author | Aleksey Kladov <aleksey.kladov@gmail.com> | 2020-06-02 14:33:47 +0200 |
|---|---|---|
| committer | Aleksey Kladov <aleksey.kladov@gmail.com> | 2020-06-02 14:52:55 +0200 |
| commit | 0ced18eee00c53e2c060f674918255844edf30a6 (patch) | |
| tree | 1f8936df9341a486ec5cd176bce50b7e46718644 /editors/code/src/debug.ts | |
| parent | 131ccd95403e10131d6b8dfcad60ebc49c257c53 (diff) | |
| download | rust-0ced18eee00c53e2c060f674918255844edf30a6.tar.gz rust-0ced18eee00c53e2c060f674918255844edf30a6.zip | |
Move run commands to commands.ts
Diffstat (limited to 'editors/code/src/debug.ts')
| -rw-r--r-- | editors/code/src/debug.ts | 119 |
1 files changed, 71 insertions, 48 deletions
diff --git a/editors/code/src/debug.ts b/editors/code/src/debug.ts index bdec5b7357f..1e421d407ba 100644 --- a/editors/code/src/debug.ts +++ b/editors/code/src/debug.ts @@ -9,40 +9,53 @@ import { Ctx } from "./ctx"; const debugOutput = vscode.window.createOutputChannel("Debug"); type DebugConfigProvider = (config: ra.Runnable, executable: string, sourceFileMap?: Record<string, string>) => vscode.DebugConfiguration; -function getLldbDebugConfig(config: ra.Runnable, executable: string, sourceFileMap?: Record<string, string>): vscode.DebugConfiguration { - return { - type: "lldb", - request: "launch", - name: config.label, - program: executable, - args: config.extraArgs, - cwd: config.cwd, - sourceMap: sourceFileMap, - sourceLanguages: ["rust"] - }; -} +export async function makeDebugConfig(ctx: Ctx, runnable: ra.Runnable): Promise<void> { + const scope = ctx.activeRustEditor?.document.uri; + if (!scope) return; -function getCppvsDebugConfig(config: ra.Runnable, executable: string, sourceFileMap?: Record<string, string>): vscode.DebugConfiguration { - return { - type: (os.platform() === "win32") ? "cppvsdbg" : "cppdbg", - request: "launch", - name: config.label, - program: executable, - args: config.extraArgs, - cwd: config.cwd, - sourceFileMap: sourceFileMap, - }; + const debugConfig = await getDebugConfiguration(ctx, runnable); + if (!debugConfig) return; + + const wsLaunchSection = vscode.workspace.getConfiguration("launch", scope); + const configurations = wsLaunchSection.get<any[]>("configurations") || []; + + const index = configurations.findIndex(c => c.name === debugConfig.name); + if (index !== -1) { + const answer = await vscode.window.showErrorMessage(`Launch configuration '${debugConfig.name}' already exists!`, 'Cancel', 'Update'); + if (answer === "Cancel") return; + + configurations[index] = debugConfig; + } else { + configurations.push(debugConfig); + } + + await wsLaunchSection.update("configurations", configurations); } -async function getDebugExecutable(config: ra.Runnable): Promise<string> { - const cargo = new Cargo(config.cwd || '.', debugOutput); - const executable = await cargo.executableFromArgs(config.args); +export async function startDebugSession(ctx: Ctx, runnable: ra.Runnable): Promise<boolean> { + let debugConfig: vscode.DebugConfiguration | undefined = undefined; + let message = ""; - // if we are here, there were no compilation errors. - return executable; + const wsLaunchSection = vscode.workspace.getConfiguration("launch"); + const configurations = wsLaunchSection.get<any[]>("configurations") || []; + + const index = configurations.findIndex(c => c.name === runnable.label); + if (-1 !== index) { + debugConfig = configurations[index]; + message = " (from launch.json)"; + debugOutput.clear(); + } else { + debugConfig = await getDebugConfiguration(ctx, runnable); + } + + if (!debugConfig) return false; + + debugOutput.appendLine(`Launching debug configuration${message}:`); + debugOutput.appendLine(JSON.stringify(debugConfig, null, 2)); + return vscode.debug.startDebugging(undefined, debugConfig); } -export async function getDebugConfiguration(ctx: Ctx, config: ra.Runnable): Promise<vscode.DebugConfiguration | undefined> { +async function getDebugConfiguration(ctx: Ctx, runnable: ra.Runnable): Promise<vscode.DebugConfiguration | undefined> { const editor = ctx.activeRustEditor; if (!editor) return; @@ -78,8 +91,8 @@ export async function getDebugConfiguration(ctx: Ctx, config: ra.Runnable): Prom return path.normalize(p).replace(wsFolder, '${workspaceRoot}'); } - const executable = await getDebugExecutable(config); - const debugConfig = knownEngines[debugEngine.id](config, simplifyPath(executable), debugOptions.sourceFileMap); + const executable = await getDebugExecutable(runnable); + const debugConfig = knownEngines[debugEngine.id](runnable, simplifyPath(executable), debugOptions.sourceFileMap); if (debugConfig.type in debugOptions.engineSettings) { const settingsMap = (debugOptions.engineSettings as any)[debugConfig.type]; for (var key in settingsMap) { @@ -100,25 +113,35 @@ export async function getDebugConfiguration(ctx: Ctx, config: ra.Runnable): Prom return debugConfig; } -export async function startDebugSession(ctx: Ctx, config: ra.Runnable): Promise<boolean> { - let debugConfig: vscode.DebugConfiguration | undefined = undefined; - let message = ""; - - const wsLaunchSection = vscode.workspace.getConfiguration("launch"); - const configurations = wsLaunchSection.get<any[]>("configurations") || []; +async function getDebugExecutable(runnable: ra.Runnable): Promise<string> { + const cargo = new Cargo(runnable.cwd || '.', debugOutput); + const executable = await cargo.executableFromArgs(runnable.args); - const index = configurations.findIndex(c => c.name === config.label); - if (-1 !== index) { - debugConfig = configurations[index]; - message = " (from launch.json)"; - debugOutput.clear(); - } else { - debugConfig = await getDebugConfiguration(ctx, config); - } + // if we are here, there were no compilation errors. + return executable; +} - if (!debugConfig) return false; +function getLldbDebugConfig(runnable: ra.Runnable, executable: string, sourceFileMap?: Record<string, string>): vscode.DebugConfiguration { + return { + type: "lldb", + request: "launch", + name: runnable.label, + program: executable, + args: runnable.extraArgs, + cwd: runnable.cwd, + sourceMap: sourceFileMap, + sourceLanguages: ["rust"] + }; +} - debugOutput.appendLine(`Launching debug configuration${message}:`); - debugOutput.appendLine(JSON.stringify(debugConfig, null, 2)); - return vscode.debug.startDebugging(undefined, debugConfig); +function getCppvsDebugConfig(runnable: ra.Runnable, executable: string, sourceFileMap?: Record<string, string>): vscode.DebugConfiguration { + return { + type: (os.platform() === "win32") ? "cppvsdbg" : "cppdbg", + request: "launch", + name: runnable.label, + program: executable, + args: runnable.extraArgs, + cwd: runnable.cwd, + sourceFileMap: sourceFileMap, + }; } |
