"rust-analyzer.newDebugConfig" command

This commit is contained in:
vsrs 2020-05-11 18:00:15 +03:00
parent 155f060142
commit fee0a9fa5a
4 changed files with 36 additions and 3 deletions

View File

@ -125,6 +125,11 @@
"title": "Debug", "title": "Debug",
"category": "Rust Analyzer" "category": "Rust Analyzer"
}, },
{
"command": "rust-analyzer.newDebugConfig",
"title": "Generate launch configuration",
"category": "Rust Analyzer"
},
{ {
"command": "rust-analyzer.analyzerStatus", "command": "rust-analyzer.analyzerStatus",
"title": "Status", "title": "Status",

View File

@ -3,7 +3,7 @@ import * as lc from 'vscode-languageclient';
import * as ra from '../rust-analyzer-api'; import * as ra from '../rust-analyzer-api';
import { Ctx, Cmd } from '../ctx'; import { Ctx, Cmd } from '../ctx';
import { startDebugSession } from '../debug'; import { startDebugSession, getDebugConfiguration } from '../debug';
async function selectRunnable(ctx: Ctx, prevRunnable: RunnableQuickPick | undefined): Promise<RunnableQuickPick | undefined> { async function selectRunnable(ctx: Ctx, prevRunnable: RunnableQuickPick | undefined): Promise<RunnableQuickPick | undefined> {
const editor = ctx.activeRustEditor; 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<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);
};
}
class RunnableQuickPick implements vscode.QuickPickItem { class RunnableQuickPick implements vscode.QuickPickItem {
public label: string; public label: string;
public description?: string | undefined; public description?: string | undefined;

View File

@ -57,8 +57,7 @@ export async function getDebugConfiguration(ctx: Ctx, config: ra.Runnable): Prom
debugEngine = vscode.extensions.getExtension(engineId); debugEngine = vscode.extensions.getExtension(engineId);
if (debugEngine) break; if (debugEngine) break;
} }
} } else {
else {
debugEngine = vscode.extensions.getExtension(debugOptions.engine); debugEngine = vscode.extensions.getExtension(debugOptions.engine);
} }

View File

@ -78,6 +78,7 @@ export async function activate(context: vscode.ExtensionContext) {
ctx.registerCommand('expandMacro', commands.expandMacro); ctx.registerCommand('expandMacro', commands.expandMacro);
ctx.registerCommand('run', commands.run); ctx.registerCommand('run', commands.run);
ctx.registerCommand('debug', commands.debug); ctx.registerCommand('debug', commands.debug);
ctx.registerCommand('newDebugConfig', commands.newDebugConfig);
defaultOnEnter.dispose(); defaultOnEnter.dispose();
ctx.registerCommand('onEnter', commands.onEnter); ctx.registerCommand('onEnter', commands.onEnter);