aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/commands/runnables.ts
diff options
context:
space:
mode:
authorvsrs <[email protected]>2020-05-11 16:00:15 +0100
committervsrs <[email protected]>2020-05-11 16:04:49 +0100
commitfee0a9fa5a3dd84400108b33a1e8225dc364a9fa (patch)
treeba411eddbb324a6e882b8fc653db17dc58c5ce2a /editors/code/src/commands/runnables.ts
parent155f0601421620086a256c9e313568d5bd7391e0 (diff)
"rust-analyzer.newDebugConfig" command
Diffstat (limited to 'editors/code/src/commands/runnables.ts')
-rw-r--r--editors/code/src/commands/runnables.ts30
1 files changed, 29 insertions, 1 deletions
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';
3import * as ra from '../rust-analyzer-api'; 3import * as ra from '../rust-analyzer-api';
4 4
5import { Ctx, Cmd } from '../ctx'; 5import { Ctx, Cmd } from '../ctx';
6import { startDebugSession } from '../debug'; 6import { startDebugSession, getDebugConfiguration } from '../debug';
7 7
8async function selectRunnable(ctx: Ctx, prevRunnable: RunnableQuickPick | undefined): Promise<RunnableQuickPick | undefined> { 8async function selectRunnable(ctx: Ctx, prevRunnable: RunnableQuickPick | undefined): Promise<RunnableQuickPick | undefined> {
9 const editor = ctx.activeRustEditor; 9 const editor = ctx.activeRustEditor;
@@ -86,6 +86,34 @@ export function debugSingle(ctx: Ctx): Cmd {
86 }; 86 };
87} 87}
88 88
89export function newDebugConfig(ctx: Ctx): Cmd {
90 return async () => {
91 const scope = ctx.activeRustEditor?.document.uri;
92 if (!scope) return;
93
94 const item = await selectRunnable(ctx, undefined);
95 if (!item) return;
96
97 const debugConfig = await getDebugConfiguration(ctx, item.runnable);
98 if (!debugConfig) return;
99
100 const wsLaunchSection = vscode.workspace.getConfiguration("launch", scope);
101 const configurations = wsLaunchSection.get<any[]>("configurations") || [];
102
103 const index = configurations.findIndex(c => c.name === debugConfig.name);
104 if (index !== -1) {
105 const answer = await vscode.window.showErrorMessage(`Launch configuration '${debugConfig.name}' already exists!`, 'Cancel', 'Update');
106 if (answer === "Cancel") return;
107
108 configurations[index] = debugConfig;
109 } else {
110 configurations.push(debugConfig);
111 }
112
113 await wsLaunchSection.update("configurations", configurations);
114 };
115}
116
89class RunnableQuickPick implements vscode.QuickPickItem { 117class RunnableQuickPick implements vscode.QuickPickItem {
90 public label: string; 118 public label: string;
91 public description?: string | undefined; 119 public description?: string | undefined;