From c4ca6e29c25df209c2733ef24b8b4eca70ee93a4 Mon Sep 17 00:00:00 2001 From: vsrs Date: Wed, 6 May 2020 16:01:35 +0300 Subject: Uniformed way to get Debug Lens target executable. --- editors/code/src/commands/runnables.ts | 59 +++++++++++++++++++--------------- editors/code/src/config.ts | 6 ++-- 2 files changed, 37 insertions(+), 28 deletions(-) diff --git a/editors/code/src/commands/runnables.ts b/editors/code/src/commands/runnables.ts index d77e8188c..7bb8727e7 100644 --- a/editors/code/src/commands/runnables.ts +++ b/editors/code/src/commands/runnables.ts @@ -64,29 +64,19 @@ export function runSingle(ctx: Ctx): Cmd { }; } -function getLldbDebugConfig(config: ra.Runnable, sourceFileMap: Record): vscode.DebugConfiguration { +function getLldbDebugConfig(config: ra.Runnable, executable: string, sourceFileMap?: Record): vscode.DebugConfiguration { return { type: "lldb", request: "launch", name: config.label, - cargo: { - args: config.args, - }, + program: executable, args: config.extraArgs, cwd: config.cwd, sourceMap: sourceFileMap }; } -const debugOutput = vscode.window.createOutputChannel("Debug"); - -async function getCppvsDebugConfig(config: ra.Runnable, sourceFileMap: Record): Promise { - debugOutput.clear(); - - const cargo = new Cargo(config.cwd || '.', debugOutput); - const executable = await cargo.executableFromArgs(config.args); - - // if we are here, there were no compilation errors. +function getCppvsDebugConfig(config: ra.Runnable, executable: string, sourceFileMap?: Record): vscode.DebugConfiguration { return { type: (os.platform() === "win32") ? "cppvsdbg" : 'cppdbg', request: "launch", @@ -98,36 +88,53 @@ async function getCppvsDebugConfig(config: ra.Runnable, sourceFileMap: Record { + debugOutput.clear(); + + const cargo = new Cargo(config.cwd || '.', debugOutput); + const executable = await cargo.executableFromArgs(config.args); + + // if we are here, there were no compilation errors. + return executable; +} + +type DebugConfigProvider = (config: ra.Runnable, executable: string, sourceFileMap?: Record) => vscode.DebugConfiguration; + export function debugSingle(ctx: Ctx): Cmd { return async (config: ra.Runnable) => { const editor = ctx.activeRustEditor; if (!editor) return; - const lldbId = "vadimcn.vscode-lldb"; - const cpptoolsId = "ms-vscode.cpptools"; + const knownEngines: Record = { + "vadimcn.vscode-lldb": getLldbDebugConfig, + "ms-vscode.cpptools": getCppvsDebugConfig + }; + const debugOptions = ctx.config.debug; - const debugEngineId = ctx.config.debug.engine; let debugEngine = null; - if (debugEngineId === "auto") { - debugEngine = vscode.extensions.getExtension(lldbId); - if (!debugEngine) { - debugEngine = vscode.extensions.getExtension(cpptoolsId); + if (debugOptions.engine === "auto") { + for (var engineId in knownEngines) { + debugEngine = vscode.extensions.getExtension(engineId); + if (debugEngine) break; } } else { - debugEngine = vscode.extensions.getExtension(debugEngineId); + debugEngine = vscode.extensions.getExtension(debugOptions.engine); } if (!debugEngine) { - vscode.window.showErrorMessage(`Install [CodeLLDB](https://marketplace.visualstudio.com/items?itemName=${lldbId})` - + ` or [MS C++ tools](https://marketplace.visualstudio.com/items?itemName=${cpptoolsId}) extension for debugging.`); + 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.`); return; } - const debugConfig = lldbId === debugEngine.id - ? getLldbDebugConfig(config, ctx.config.debug.sourceFileMap) - : await getCppvsDebugConfig(config, ctx.config.debug.sourceFileMap); + const executable = await getDebugExecutable(config); + const debugConfig = knownEngines[debugEngine.id](config, executable, debugOptions.sourceFileMap); + debugOutput.appendLine("Launching debug configuration:"); + debugOutput.appendLine(JSON.stringify(debugConfig, null, 2)); return vscode.debug.startDebugging(undefined, debugConfig); }; } diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index 110e54180..8bceaaf72 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts @@ -108,10 +108,12 @@ export class Config { } get debug() { + // "/rustc/" used by suggestions only. + const { ["/rustc/"]: _, ...sourceFileMap } = this.get>("debug.sourceFileMap"); + return { engine: this.get("debug.engine"), - sourceFileMap: this.get>("debug.sourceFileMap"), + sourceFileMap: sourceFileMap, }; } - } -- cgit v1.2.3 From 5426e2927e317a5e78179a5bd74b9414c0651b86 Mon Sep 17 00:00:00 2001 From: vsrs Date: Thu, 7 May 2020 17:07:58 +0300 Subject: Add additional debug options --- editors/code/package.json | 10 ++++++++++ editors/code/src/commands/runnables.ts | 12 +++++++++--- editors/code/src/config.ts | 2 ++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/editors/code/package.json b/editors/code/package.json index eeb3d3513..84aea8249 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -418,6 +418,16 @@ "default": { "/rustc/": "${env:USERPROFILE}/.rustup/toolchains//lib/rustlib/src/rust" } + }, + "rust-analyzer.debug.openUpDebugPane": { + "description": "Whether to open up the Debug Pane on debugging start.", + "type": "boolean", + "default": false + }, + "rust-analyzer.debug.engineSettings": { + "type": "object", + "default": {}, + "description": "Optional settings passed to the debug engine." } } }, diff --git a/editors/code/src/commands/runnables.ts b/editors/code/src/commands/runnables.ts index 7bb8727e7..782a7ba89 100644 --- a/editors/code/src/commands/runnables.ts +++ b/editors/code/src/commands/runnables.ts @@ -91,8 +91,6 @@ function getCppvsDebugConfig(config: ra.Runnable, executable: string, sourceFile const debugOutput = vscode.window.createOutputChannel("Debug"); async function getDebugExecutable(config: ra.Runnable): Promise { - debugOutput.clear(); - const cargo = new Cargo(config.cwd || '.', debugOutput); const executable = await cargo.executableFromArgs(config.args); @@ -130,8 +128,16 @@ export function debugSingle(ctx: Ctx): Cmd { return; } + debugOutput.clear(); + if (ctx.config.debug.openUpDebugPane) { + debugOutput.show(true); + } + const executable = await getDebugExecutable(config); - const debugConfig = knownEngines[debugEngine.id](config, executable, debugOptions.sourceFileMap); + let debugConfig = knownEngines[debugEngine.id](config, executable, debugOptions.sourceFileMap); + for (var key in debugOptions.engineSettings) { + debugConfig[key] = (debugOptions.engineSettings as any)[key]; + } debugOutput.appendLine("Launching debug configuration:"); debugOutput.appendLine(JSON.stringify(debugConfig, null, 2)); diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index 8bceaaf72..533be1913 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts @@ -113,6 +113,8 @@ export class Config { return { engine: this.get("debug.engine"), + engineSettings: this.get("debug.engineSettings"), + openUpDebugPane: this.get("debug.openUpDebugPane"), sourceFileMap: sourceFileMap, }; } -- cgit v1.2.3 From 435a17ecd8806f3ae81edf6277c17363b01f4334 Mon Sep 17 00:00:00 2001 From: vsrs Date: Thu, 7 May 2020 18:35:48 +0300 Subject: Add separate settings for each debug engine. --- editors/code/package.json | 4 ++-- editors/code/src/commands/runnables.ts | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/editors/code/package.json b/editors/code/package.json index 84aea8249..e4dd66924 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -427,7 +427,7 @@ "rust-analyzer.debug.engineSettings": { "type": "object", "default": {}, - "description": "Optional settings passed to the debug engine." + "description": "Optional settings passed to the debug engine. Example:\n{ \"lldb\": { \"terminal\":\"external\"} }" } } }, @@ -609,4 +609,4 @@ } ] } -} +} \ No newline at end of file diff --git a/editors/code/src/commands/runnables.ts b/editors/code/src/commands/runnables.ts index 782a7ba89..e62de7d6e 100644 --- a/editors/code/src/commands/runnables.ts +++ b/editors/code/src/commands/runnables.ts @@ -134,9 +134,12 @@ export function debugSingle(ctx: Ctx): Cmd { } const executable = await getDebugExecutable(config); - let debugConfig = knownEngines[debugEngine.id](config, executable, debugOptions.sourceFileMap); - for (var key in debugOptions.engineSettings) { - debugConfig[key] = (debugOptions.engineSettings as any)[key]; + const debugConfig = knownEngines[debugEngine.id](config, executable, debugOptions.sourceFileMap); + if (debugConfig.type in debugOptions.engineSettings) { + const settingsMap = (debugOptions.engineSettings as any)[debugConfig.type]; + for (var key in settingsMap) { + debugConfig[key] = settingsMap[key]; + } } debugOutput.appendLine("Launching debug configuration:"); -- cgit v1.2.3 From 23f4859166ba16f02927b476aad2ae91e618b1ef Mon Sep 17 00:00:00 2001 From: vsrs Date: Thu, 7 May 2020 18:53:14 +0300 Subject: Add CodeLLDB Rust visualization --- editors/code/package.json | 2 +- editors/code/src/commands/runnables.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/editors/code/package.json b/editors/code/package.json index e4dd66924..e8e9598f6 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -609,4 +609,4 @@ } ] } -} \ No newline at end of file +} diff --git a/editors/code/src/commands/runnables.ts b/editors/code/src/commands/runnables.ts index e62de7d6e..ae328d2a4 100644 --- a/editors/code/src/commands/runnables.ts +++ b/editors/code/src/commands/runnables.ts @@ -72,7 +72,8 @@ function getLldbDebugConfig(config: ra.Runnable, executable: string, sourceFileM program: executable, args: config.extraArgs, cwd: config.cwd, - sourceMap: sourceFileMap + sourceMap: sourceFileMap, + sourceLanguages: ["rust"] }; } -- cgit v1.2.3 From 1be6320ea6cf7830195f80681fa0f43cc340da7e Mon Sep 17 00:00:00 2001 From: vsrs <62505555+vsrs@users.noreply.github.com> Date: Fri, 8 May 2020 19:22:26 +0300 Subject: "rust-analyzer.debug.openDebugPane" Co-authored-by: bjorn3 --- editors/code/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/editors/code/package.json b/editors/code/package.json index e8e9598f6..e750412a7 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -419,7 +419,7 @@ "/rustc/": "${env:USERPROFILE}/.rustup/toolchains//lib/rustlib/src/rust" } }, - "rust-analyzer.debug.openUpDebugPane": { + "rust-analyzer.debug.openDebugPane": { "description": "Whether to open up the Debug Pane on debugging start.", "type": "boolean", "default": false -- cgit v1.2.3