aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/run.ts
diff options
context:
space:
mode:
Diffstat (limited to 'editors/code/src/run.ts')
-rw-r--r--editors/code/src/run.ts74
1 files changed, 3 insertions, 71 deletions
diff --git a/editors/code/src/run.ts b/editors/code/src/run.ts
index 113354bab..5fc4f8e41 100644
--- a/editors/code/src/run.ts
+++ b/editors/code/src/run.ts
@@ -3,8 +3,8 @@ import * as lc from 'vscode-languageclient';
3import * as ra from './lsp_ext'; 3import * as ra from './lsp_ext';
4import * as toolchain from "./toolchain"; 4import * as toolchain from "./toolchain";
5 5
6import { Ctx, Cmd } from './ctx'; 6import { Ctx } from './ctx';
7import { startDebugSession, getDebugConfiguration } from './debug'; 7import { makeDebugConfig } from './debug';
8 8
9const quickPickButtons = [{ iconPath: new vscode.ThemeIcon("save"), tooltip: "Save as a launch.json configurtation." }]; 9const quickPickButtons = [{ iconPath: new vscode.ThemeIcon("save"), tooltip: "Save as a launch.json configurtation." }];
10 10
@@ -65,7 +65,7 @@ export async function selectRunnable(ctx: Ctx, prevRunnable?: RunnableQuickPick,
65 quickPick.onDidHide(() => close()), 65 quickPick.onDidHide(() => close()),
66 quickPick.onDidAccept(() => close(quickPick.selectedItems[0])), 66 quickPick.onDidAccept(() => close(quickPick.selectedItems[0])),
67 quickPick.onDidTriggerButton((_button) => { 67 quickPick.onDidTriggerButton((_button) => {
68 (async () => await makeDebugConfig(ctx, quickPick.activeItems[0]))(); 68 (async () => await makeDebugConfig(ctx, quickPick.activeItems[0].runnable))();
69 close(); 69 close();
70 }), 70 }),
71 quickPick.onDidChangeActive((active) => { 71 quickPick.onDidChangeActive((active) => {
@@ -84,74 +84,6 @@ export async function selectRunnable(ctx: Ctx, prevRunnable?: RunnableQuickPick,
84 }); 84 });
85} 85}
86 86
87export function runSingle(ctx: Ctx): Cmd {
88 return async (runnable: ra.Runnable) => {
89 const editor = ctx.activeRustEditor;
90 if (!editor) return;
91
92 const task = createTask(runnable);
93 task.group = vscode.TaskGroup.Build;
94 task.presentationOptions = {
95 reveal: vscode.TaskRevealKind.Always,
96 panel: vscode.TaskPanelKind.Dedicated,
97 clear: true,
98 };
99
100 return vscode.tasks.executeTask(task);
101 };
102}
103
104export function debug(ctx: Ctx): Cmd {
105 let prevDebuggee: RunnableQuickPick | undefined;
106
107 return async () => {
108 const item = await selectRunnable(ctx, prevDebuggee, true);
109 if (!item) return;
110
111 item.detail = 'restart';
112 prevDebuggee = item;
113 return await startDebugSession(ctx, item.runnable);
114 };
115}
116
117export function debugSingle(ctx: Ctx): Cmd {
118 return async (config: ra.Runnable) => {
119 await startDebugSession(ctx, config);
120 };
121}
122
123async function makeDebugConfig(ctx: Ctx, item: RunnableQuickPick): Promise<void> {
124 const scope = ctx.activeRustEditor?.document.uri;
125 if (!scope) return;
126
127 const debugConfig = await getDebugConfiguration(ctx, item.runnable);
128 if (!debugConfig) return;
129
130 const wsLaunchSection = vscode.workspace.getConfiguration("launch", scope);
131 const configurations = wsLaunchSection.get<any[]>("configurations") || [];
132
133 const index = configurations.findIndex(c => c.name === debugConfig.name);
134 if (index !== -1) {
135 const answer = await vscode.window.showErrorMessage(`Launch configuration '${debugConfig.name}' already exists!`, 'Cancel', 'Update');
136 if (answer === "Cancel") return;
137
138 configurations[index] = debugConfig;
139 } else {
140 configurations.push(debugConfig);
141 }
142
143 await wsLaunchSection.update("configurations", configurations);
144}
145
146export function newDebugConfig(ctx: Ctx): Cmd {
147 return async () => {
148 const item = await selectRunnable(ctx, undefined, true, false);
149 if (!item) return;
150
151 await makeDebugConfig(ctx, item);
152 };
153}
154
155export class RunnableQuickPick implements vscode.QuickPickItem { 87export class RunnableQuickPick implements vscode.QuickPickItem {
156 public label: string; 88 public label: string;
157 public description?: string | undefined; 89 public description?: string | undefined;