mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
"rust-analyzer.newDebugConfig" command
This commit is contained in:
parent
155f060142
commit
fee0a9fa5a
4 changed files with 36 additions and 3 deletions
|
@ -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",
|
||||
|
|
|
@ -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<RunnableQuickPick | undefined> {
|
||||
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 {
|
||||
public label: string;
|
||||
public description?: string | undefined;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue