From 155f0601421620086a256c9e313568d5bd7391e0 Mon Sep 17 00:00:00 2001 From: vsrs Date: Mon, 11 May 2020 16:06:57 +0300 Subject: "rust-analyzer.debug" command --- editors/code/src/debug.ts | 95 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 editors/code/src/debug.ts (limited to 'editors/code/src/debug.ts') diff --git a/editors/code/src/debug.ts b/editors/code/src/debug.ts new file mode 100644 index 000000000..4f4b88adf --- /dev/null +++ b/editors/code/src/debug.ts @@ -0,0 +1,95 @@ +import * as os from "os"; +import * as vscode from 'vscode'; +import * as ra from './rust-analyzer-api'; + +import { Cargo } from './cargo'; +import { Ctx } from "./ctx"; + +const debugOutput = vscode.window.createOutputChannel("Debug"); +type DebugConfigProvider = (config: ra.Runnable, executable: string, sourceFileMap?: Record) => vscode.DebugConfiguration; + +function getLldbDebugConfig(config: ra.Runnable, executable: string, sourceFileMap?: Record): vscode.DebugConfiguration { + return { + type: "lldb", + request: "launch", + name: config.label, + program: executable, + args: config.extraArgs, + cwd: config.cwd, + sourceMap: sourceFileMap, + sourceLanguages: ["rust"] + }; +} + +function getCppvsDebugConfig(config: ra.Runnable, executable: string, sourceFileMap?: Record): vscode.DebugConfiguration { + return { + type: (os.platform() === "win32") ? "cppvsdbg" : "cppdbg", + request: "launch", + name: config.label, + program: executable, + args: config.extraArgs, + cwd: config.cwd, + sourceFileMap: sourceFileMap, + }; +} + +async function getDebugExecutable(config: ra.Runnable): Promise { + 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; +} + +export async function getDebugConfiguration(ctx: Ctx, config: ra.Runnable): Promise { + const editor = ctx.activeRustEditor; + if (!editor) return; + + const knownEngines: Record = { + "vadimcn.vscode-lldb": getLldbDebugConfig, + "ms-vscode.cpptools": getCppvsDebugConfig + }; + const debugOptions = ctx.config.debug; + + let debugEngine = null; + if (debugOptions.engine === "auto") { + for (var engineId in knownEngines) { + debugEngine = vscode.extensions.getExtension(engineId); + if (debugEngine) break; + } + } + else { + debugEngine = vscode.extensions.getExtension(debugOptions.engine); + } + + if (!debugEngine) { + 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; + } + + debugOutput.clear(); + if (ctx.config.debug.openUpDebugPane) { + debugOutput.show(true); + } + + const executable = await getDebugExecutable(config); + 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]; + } + } + + return debugConfig; +} + +export async function startDebugSession(ctx: Ctx, config: ra.Runnable): Promise { + const debugConfig = await getDebugConfiguration(ctx, config); + if (!debugConfig) return false; + + debugOutput.appendLine("Launching debug configuration:"); + debugOutput.appendLine(JSON.stringify(debugConfig, null, 2)); + return vscode.debug.startDebugging(undefined, debugConfig); +} -- cgit v1.2.3 From fee0a9fa5a3dd84400108b33a1e8225dc364a9fa Mon Sep 17 00:00:00 2001 From: vsrs Date: Mon, 11 May 2020 18:00:15 +0300 Subject: "rust-analyzer.newDebugConfig" command --- editors/code/src/debug.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'editors/code/src/debug.ts') diff --git a/editors/code/src/debug.ts b/editors/code/src/debug.ts index 4f4b88adf..228a7ab75 100644 --- a/editors/code/src/debug.ts +++ b/editors/code/src/debug.ts @@ -57,8 +57,7 @@ export async function getDebugConfiguration(ctx: Ctx, config: ra.Runnable): Prom debugEngine = vscode.extensions.getExtension(engineId); if (debugEngine) break; } - } - else { + } else { debugEngine = vscode.extensions.getExtension(debugOptions.engine); } -- cgit v1.2.3 From e914d622ec378fd9efb9b20801c925ade806ef60 Mon Sep 17 00:00:00 2001 From: vsrs Date: Mon, 11 May 2020 18:49:45 +0300 Subject: DebugConfiguration simplification. ${workspaceRoot} substitution in generated DebugConfiguration. --- editors/code/src/debug.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'editors/code/src/debug.ts') diff --git a/editors/code/src/debug.ts b/editors/code/src/debug.ts index 228a7ab75..cc5755611 100644 --- a/editors/code/src/debug.ts +++ b/editors/code/src/debug.ts @@ -1,5 +1,6 @@ import * as os from "os"; import * as vscode from 'vscode'; +import * as path from 'path'; import * as ra from './rust-analyzer-api'; import { Cargo } from './cargo'; @@ -72,8 +73,13 @@ export async function getDebugConfiguration(ctx: Ctx, config: ra.Runnable): Prom debugOutput.show(true); } + const wsFolder = path.normalize(vscode.workspace.workspaceFolders![0].uri.fsPath); // folder exists or RA is not active. + function simplifyPath(p: string): string { + return path.normalize(p).replace(wsFolder, '${workspaceRoot}'); + } + const executable = await getDebugExecutable(config); - const debugConfig = knownEngines[debugEngine.id](config, executable, debugOptions.sourceFileMap); + const debugConfig = knownEngines[debugEngine.id](config, simplifyPath(executable), debugOptions.sourceFileMap); if (debugConfig.type in debugOptions.engineSettings) { const settingsMap = (debugOptions.engineSettings as any)[debugConfig.type]; for (var key in settingsMap) { @@ -81,6 +87,10 @@ export async function getDebugConfiguration(ctx: Ctx, config: ra.Runnable): Prom } } + if (debugConfig.cwd) { + debugConfig.cwd = simplifyPath(debugConfig.cwd); + } + return debugConfig; } -- cgit v1.2.3 From 9ebb2acdca6c711cff7bfc84a410794739092dbe Mon Sep 17 00:00:00 2001 From: vsrs Date: Wed, 13 May 2020 15:51:15 +0300 Subject: Use launch.json in Debug Lens sessions. Add the possibility to use existing configurations via Debug Lens --- editors/code/src/debug.ts | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'editors/code/src/debug.ts') diff --git a/editors/code/src/debug.ts b/editors/code/src/debug.ts index cc5755611..bbf3ff312 100644 --- a/editors/code/src/debug.ts +++ b/editors/code/src/debug.ts @@ -95,10 +95,27 @@ export async function getDebugConfiguration(ctx: Ctx, config: ra.Runnable): Prom } export async function startDebugSession(ctx: Ctx, config: ra.Runnable): Promise { - const debugConfig = await getDebugConfiguration(ctx, config); + let debugConfig: vscode.DebugConfiguration | undefined = undefined; + let message = ""; + + if (ctx.config.debug.useLaunchJson) { + const wsLaunchSection = vscode.workspace.getConfiguration("launch"); + const configurations = wsLaunchSection.get("configurations") || []; + + const index = configurations.findIndex(c => c.name === config.label); + if (-1 !== index) { + debugConfig = configurations[index]; + message = " (from launch.json)"; + debugOutput.clear(); + } + } + if (!debugConfig) { + debugConfig = await getDebugConfiguration(ctx, config); + } + if (!debugConfig) return false; - debugOutput.appendLine("Launching debug configuration:"); + debugOutput.appendLine(`Launching debug configuration${message}:`); debugOutput.appendLine(JSON.stringify(debugConfig, null, 2)); return vscode.debug.startDebugging(undefined, debugConfig); } -- cgit v1.2.3 From 3ffc26eaebb1f9491477e99d5187b048bd489cd6 Mon Sep 17 00:00:00 2001 From: vsrs Date: Thu, 14 May 2020 11:12:10 +0300 Subject: Remove "rust-analyzer.debug.useLaunchJson" option --- editors/code/src/debug.ts | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'editors/code/src/debug.ts') diff --git a/editors/code/src/debug.ts b/editors/code/src/debug.ts index bbf3ff312..b500fe029 100644 --- a/editors/code/src/debug.ts +++ b/editors/code/src/debug.ts @@ -98,18 +98,15 @@ export async function startDebugSession(ctx: Ctx, config: ra.Runnable): Promise< let debugConfig: vscode.DebugConfiguration | undefined = undefined; let message = ""; - if (ctx.config.debug.useLaunchJson) { - const wsLaunchSection = vscode.workspace.getConfiguration("launch"); - const configurations = wsLaunchSection.get("configurations") || []; - - const index = configurations.findIndex(c => c.name === config.label); - if (-1 !== index) { - debugConfig = configurations[index]; - message = " (from launch.json)"; - debugOutput.clear(); - } - } - if (!debugConfig) { + const wsLaunchSection = vscode.workspace.getConfiguration("launch"); + const configurations = wsLaunchSection.get("configurations") || []; + + 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); } -- cgit v1.2.3 From af7c50f8a2e6763d4d72d0fa0b33e62b12aaf1c7 Mon Sep 17 00:00:00 2001 From: vsrs Date: Thu, 14 May 2020 13:48:02 +0300 Subject: Multiple binaries support for launch.json. --- editors/code/src/debug.ts | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'editors/code/src/debug.ts') diff --git a/editors/code/src/debug.ts b/editors/code/src/debug.ts index b500fe029..966019883 100644 --- a/editors/code/src/debug.ts +++ b/editors/code/src/debug.ts @@ -87,6 +87,11 @@ export async function getDebugConfiguration(ctx: Ctx, config: ra.Runnable): Prom } } + if (debugConfig.name === "run binary") { + // A workaround for multiple binaries. It would be better to get proper names on the LSP side. + debugConfig.name = `run binary [${path.basename(executable)}]`; + } + if (debugConfig.cwd) { debugConfig.cwd = simplifyPath(debugConfig.cwd); } -- cgit v1.2.3 From 20fdd14c62aa9c5327f1e6afc04f01a5af6763fb Mon Sep 17 00:00:00 2001 From: vsrs Date: Thu, 14 May 2020 16:02:01 +0300 Subject: Multiple binaries support for launch.json. Generate unique names on the LSP side. --- editors/code/src/debug.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'editors/code/src/debug.ts') diff --git a/editors/code/src/debug.ts b/editors/code/src/debug.ts index 966019883..1f93a2b7e 100644 --- a/editors/code/src/debug.ts +++ b/editors/code/src/debug.ts @@ -88,8 +88,9 @@ export async function getDebugConfiguration(ctx: Ctx, config: ra.Runnable): Prom } if (debugConfig.name === "run binary") { - // A workaround for multiple binaries. It would be better to get proper names on the LSP side. - debugConfig.name = `run binary [${path.basename(executable)}]`; + // The LSP side: crates\rust-analyzer\src\main_loop\handlers.rs, + // fn to_lsp_runnable(...) with RunnableKind::Bin + debugConfig.name = `run binary '${path.basename(executable)}'`; } if (debugConfig.cwd) { -- cgit v1.2.3 From abef76bc87137203081faedd3c758796e8d6598d Mon Sep 17 00:00:00 2001 From: vsrs Date: Thu, 14 May 2020 17:32:24 +0300 Subject: Fix runnable naming in the client side fallback. --- editors/code/src/debug.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'editors/code/src/debug.ts') diff --git a/editors/code/src/debug.ts b/editors/code/src/debug.ts index 1f93a2b7e..d3fe588e8 100644 --- a/editors/code/src/debug.ts +++ b/editors/code/src/debug.ts @@ -90,7 +90,7 @@ export async function getDebugConfiguration(ctx: Ctx, config: ra.Runnable): Prom if (debugConfig.name === "run binary") { // The LSP side: crates\rust-analyzer\src\main_loop\handlers.rs, // fn to_lsp_runnable(...) with RunnableKind::Bin - debugConfig.name = `run binary '${path.basename(executable)}'`; + debugConfig.name = `run ${path.basename(executable)}`; } if (debugConfig.cwd) { -- cgit v1.2.3