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/package.json | 5 +++++ editors/code/src/commands/runnables.ts | 30 +++++++++++++++++++++++++++++- editors/code/src/debug.ts | 3 +-- editors/code/src/main.ts | 1 + 4 files changed, 36 insertions(+), 3 deletions(-) (limited to 'editors') diff --git a/editors/code/package.json b/editors/code/package.json index 2f90d3baf..ec325ad3f 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -125,6 +125,11 @@ "title": "Debug", "category": "Rust Analyzer" }, + { + "command": "rust-analyzer.newDebugConfig", + "title": "Generate launch configuration", + "category": "Rust Analyzer" + }, { "command": "rust-analyzer.analyzerStatus", "title": "Status", diff --git a/editors/code/src/commands/runnables.ts b/editors/code/src/commands/runnables.ts index c1b872bce..5e88eeae0 100644 --- a/editors/code/src/commands/runnables.ts +++ b/editors/code/src/commands/runnables.ts @@ -3,7 +3,7 @@ import * as lc from 'vscode-languageclient'; import * as ra from '../rust-analyzer-api'; import { Ctx, Cmd } from '../ctx'; -import { startDebugSession } from '../debug'; +import { startDebugSession, getDebugConfiguration } from '../debug'; async function selectRunnable(ctx: Ctx, prevRunnable: RunnableQuickPick | undefined): Promise { const editor = ctx.activeRustEditor; @@ -86,6 +86,34 @@ export function debugSingle(ctx: Ctx): Cmd { }; } +export function newDebugConfig(ctx: Ctx): Cmd { + return async () => { + const scope = ctx.activeRustEditor?.document.uri; + if (!scope) return; + + const item = await selectRunnable(ctx, undefined); + if (!item) return; + + const debugConfig = await getDebugConfiguration(ctx, item.runnable); + if (!debugConfig) return; + + const wsLaunchSection = vscode.workspace.getConfiguration("launch", scope); + const configurations = wsLaunchSection.get("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); + }; +} + class RunnableQuickPick implements vscode.QuickPickItem { public label: string; public description?: string | undefined; 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); } diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts index 5fdeebd68..c015460b8 100644 --- a/editors/code/src/main.ts +++ b/editors/code/src/main.ts @@ -78,6 +78,7 @@ export async function activate(context: vscode.ExtensionContext) { ctx.registerCommand('expandMacro', commands.expandMacro); ctx.registerCommand('run', commands.run); ctx.registerCommand('debug', commands.debug); + ctx.registerCommand('newDebugConfig', commands.newDebugConfig); defaultOnEnter.dispose(); ctx.registerCommand('onEnter', commands.onEnter); -- cgit v1.2.3