diff options
Diffstat (limited to 'editors/code/src')
-rw-r--r-- | editors/code/src/commands.ts | 74 | ||||
-rw-r--r-- | editors/code/src/debug.ts | 119 | ||||
-rw-r--r-- | editors/code/src/run.ts | 74 |
3 files changed, 134 insertions, 133 deletions
diff --git a/editors/code/src/commands.ts b/editors/code/src/commands.ts index 86302db37..534d2a984 100644 --- a/editors/code/src/commands.ts +++ b/editors/code/src/commands.ts | |||
@@ -8,6 +8,7 @@ import { spawnSync } from 'child_process'; | |||
8 | import { RunnableQuickPick, selectRunnable, createTask } from './run'; | 8 | import { RunnableQuickPick, selectRunnable, createTask } from './run'; |
9 | import { AstInspector } from './ast_inspector'; | 9 | import { AstInspector } from './ast_inspector'; |
10 | import { isRustDocument, sleep, isRustEditor } from './util'; | 10 | import { isRustDocument, sleep, isRustEditor } from './util'; |
11 | import { startDebugSession, makeDebugConfig } from './debug'; | ||
11 | 12 | ||
12 | export * from './ast_inspector'; | 13 | export * from './ast_inspector'; |
13 | export * from './run'; | 14 | export * from './run'; |
@@ -197,20 +198,6 @@ export function toggleInlayHints(ctx: Ctx): Cmd { | |||
197 | }; | 198 | }; |
198 | } | 199 | } |
199 | 200 | ||
200 | export function run(ctx: Ctx): Cmd { | ||
201 | let prevRunnable: RunnableQuickPick | undefined; | ||
202 | |||
203 | return async () => { | ||
204 | const item = await selectRunnable(ctx, prevRunnable); | ||
205 | if (!item) return; | ||
206 | |||
207 | item.detail = 'rerun'; | ||
208 | prevRunnable = item; | ||
209 | const task = createTask(item.runnable); | ||
210 | return await vscode.tasks.executeTask(task); | ||
211 | }; | ||
212 | } | ||
213 | |||
214 | // Opens the virtual file that will show the syntax tree | 201 | // Opens the virtual file that will show the syntax tree |
215 | // | 202 | // |
216 | // The contents of the file come from the `TextDocumentContentProvider` | 203 | // The contents of the file come from the `TextDocumentContentProvider` |
@@ -368,3 +355,62 @@ export function applySnippetWorkspaceEditCommand(_ctx: Ctx): Cmd { | |||
368 | await applySnippetWorkspaceEdit(edit); | 355 | await applySnippetWorkspaceEdit(edit); |
369 | }; | 356 | }; |
370 | } | 357 | } |
358 | |||
359 | export function run(ctx: Ctx): Cmd { | ||
360 | let prevRunnable: RunnableQuickPick | undefined; | ||
361 | |||
362 | return async () => { | ||
363 | const item = await selectRunnable(ctx, prevRunnable); | ||
364 | if (!item) return; | ||
365 | |||
366 | item.detail = 'rerun'; | ||
367 | prevRunnable = item; | ||
368 | const task = createTask(item.runnable); | ||
369 | return await vscode.tasks.executeTask(task); | ||
370 | }; | ||
371 | } | ||
372 | |||
373 | export function runSingle(ctx: Ctx): Cmd { | ||
374 | return async (runnable: ra.Runnable) => { | ||
375 | const editor = ctx.activeRustEditor; | ||
376 | if (!editor) return; | ||
377 | |||
378 | const task = createTask(runnable); | ||
379 | task.group = vscode.TaskGroup.Build; | ||
380 | task.presentationOptions = { | ||
381 | reveal: vscode.TaskRevealKind.Always, | ||
382 | panel: vscode.TaskPanelKind.Dedicated, | ||
383 | clear: true, | ||
384 | }; | ||
385 | |||
386 | return vscode.tasks.executeTask(task); | ||
387 | }; | ||
388 | } | ||
389 | |||
390 | export function debug(ctx: Ctx): Cmd { | ||
391 | let prevDebuggee: RunnableQuickPick | undefined; | ||
392 | |||
393 | return async () => { | ||
394 | const item = await selectRunnable(ctx, prevDebuggee, true); | ||
395 | if (!item) return; | ||
396 | |||
397 | item.detail = 'restart'; | ||
398 | prevDebuggee = item; | ||
399 | return await startDebugSession(ctx, item.runnable); | ||
400 | }; | ||
401 | } | ||
402 | |||
403 | export function debugSingle(ctx: Ctx): Cmd { | ||
404 | return async (config: ra.Runnable) => { | ||
405 | await startDebugSession(ctx, config); | ||
406 | }; | ||
407 | } | ||
408 | |||
409 | export function newDebugConfig(ctx: Ctx): Cmd { | ||
410 | return async () => { | ||
411 | const item = await selectRunnable(ctx, undefined, true, false); | ||
412 | if (!item) return; | ||
413 | |||
414 | await makeDebugConfig(ctx, item.runnable); | ||
415 | }; | ||
416 | } | ||
diff --git a/editors/code/src/debug.ts b/editors/code/src/debug.ts index bdec5b735..1e421d407 100644 --- a/editors/code/src/debug.ts +++ b/editors/code/src/debug.ts | |||
@@ -9,40 +9,53 @@ import { Ctx } from "./ctx"; | |||
9 | const debugOutput = vscode.window.createOutputChannel("Debug"); | 9 | const debugOutput = vscode.window.createOutputChannel("Debug"); |
10 | type DebugConfigProvider = (config: ra.Runnable, executable: string, sourceFileMap?: Record<string, string>) => vscode.DebugConfiguration; | 10 | type DebugConfigProvider = (config: ra.Runnable, executable: string, sourceFileMap?: Record<string, string>) => vscode.DebugConfiguration; |
11 | 11 | ||
12 | function getLldbDebugConfig(config: ra.Runnable, executable: string, sourceFileMap?: Record<string, string>): vscode.DebugConfiguration { | 12 | export async function makeDebugConfig(ctx: Ctx, runnable: ra.Runnable): Promise<void> { |
13 | return { | 13 | const scope = ctx.activeRustEditor?.document.uri; |
14 | type: "lldb", | 14 | if (!scope) return; |
15 | request: "launch", | ||
16 | name: config.label, | ||
17 | program: executable, | ||
18 | args: config.extraArgs, | ||
19 | cwd: config.cwd, | ||
20 | sourceMap: sourceFileMap, | ||
21 | sourceLanguages: ["rust"] | ||
22 | }; | ||
23 | } | ||
24 | 15 | ||
25 | function getCppvsDebugConfig(config: ra.Runnable, executable: string, sourceFileMap?: Record<string, string>): vscode.DebugConfiguration { | 16 | const debugConfig = await getDebugConfiguration(ctx, runnable); |
26 | return { | 17 | if (!debugConfig) return; |
27 | type: (os.platform() === "win32") ? "cppvsdbg" : "cppdbg", | 18 | |
28 | request: "launch", | 19 | const wsLaunchSection = vscode.workspace.getConfiguration("launch", scope); |
29 | name: config.label, | 20 | const configurations = wsLaunchSection.get<any[]>("configurations") || []; |
30 | program: executable, | 21 | |
31 | args: config.extraArgs, | 22 | const index = configurations.findIndex(c => c.name === debugConfig.name); |
32 | cwd: config.cwd, | 23 | if (index !== -1) { |
33 | sourceFileMap: sourceFileMap, | 24 | const answer = await vscode.window.showErrorMessage(`Launch configuration '${debugConfig.name}' already exists!`, 'Cancel', 'Update'); |
34 | }; | 25 | if (answer === "Cancel") return; |
26 | |||
27 | configurations[index] = debugConfig; | ||
28 | } else { | ||
29 | configurations.push(debugConfig); | ||
30 | } | ||
31 | |||
32 | await wsLaunchSection.update("configurations", configurations); | ||
35 | } | 33 | } |
36 | 34 | ||
37 | async function getDebugExecutable(config: ra.Runnable): Promise<string> { | 35 | export async function startDebugSession(ctx: Ctx, runnable: ra.Runnable): Promise<boolean> { |
38 | const cargo = new Cargo(config.cwd || '.', debugOutput); | 36 | let debugConfig: vscode.DebugConfiguration | undefined = undefined; |
39 | const executable = await cargo.executableFromArgs(config.args); | 37 | let message = ""; |
40 | 38 | ||
41 | // if we are here, there were no compilation errors. | 39 | const wsLaunchSection = vscode.workspace.getConfiguration("launch"); |
42 | return executable; | 40 | const configurations = wsLaunchSection.get<any[]>("configurations") || []; |
41 | |||
42 | const index = configurations.findIndex(c => c.name === runnable.label); | ||
43 | if (-1 !== index) { | ||
44 | debugConfig = configurations[index]; | ||
45 | message = " (from launch.json)"; | ||
46 | debugOutput.clear(); | ||
47 | } else { | ||
48 | debugConfig = await getDebugConfiguration(ctx, runnable); | ||
49 | } | ||
50 | |||
51 | if (!debugConfig) return false; | ||
52 | |||
53 | debugOutput.appendLine(`Launching debug configuration${message}:`); | ||
54 | debugOutput.appendLine(JSON.stringify(debugConfig, null, 2)); | ||
55 | return vscode.debug.startDebugging(undefined, debugConfig); | ||
43 | } | 56 | } |
44 | 57 | ||
45 | export async function getDebugConfiguration(ctx: Ctx, config: ra.Runnable): Promise<vscode.DebugConfiguration | undefined> { | 58 | async function getDebugConfiguration(ctx: Ctx, runnable: ra.Runnable): Promise<vscode.DebugConfiguration | undefined> { |
46 | const editor = ctx.activeRustEditor; | 59 | const editor = ctx.activeRustEditor; |
47 | if (!editor) return; | 60 | if (!editor) return; |
48 | 61 | ||
@@ -78,8 +91,8 @@ export async function getDebugConfiguration(ctx: Ctx, config: ra.Runnable): Prom | |||
78 | return path.normalize(p).replace(wsFolder, '${workspaceRoot}'); | 91 | return path.normalize(p).replace(wsFolder, '${workspaceRoot}'); |
79 | } | 92 | } |
80 | 93 | ||
81 | const executable = await getDebugExecutable(config); | 94 | const executable = await getDebugExecutable(runnable); |
82 | const debugConfig = knownEngines[debugEngine.id](config, simplifyPath(executable), debugOptions.sourceFileMap); | 95 | const debugConfig = knownEngines[debugEngine.id](runnable, simplifyPath(executable), debugOptions.sourceFileMap); |
83 | if (debugConfig.type in debugOptions.engineSettings) { | 96 | if (debugConfig.type in debugOptions.engineSettings) { |
84 | const settingsMap = (debugOptions.engineSettings as any)[debugConfig.type]; | 97 | const settingsMap = (debugOptions.engineSettings as any)[debugConfig.type]; |
85 | for (var key in settingsMap) { | 98 | for (var key in settingsMap) { |
@@ -100,25 +113,35 @@ export async function getDebugConfiguration(ctx: Ctx, config: ra.Runnable): Prom | |||
100 | return debugConfig; | 113 | return debugConfig; |
101 | } | 114 | } |
102 | 115 | ||
103 | export async function startDebugSession(ctx: Ctx, config: ra.Runnable): Promise<boolean> { | 116 | async function getDebugExecutable(runnable: ra.Runnable): Promise<string> { |
104 | let debugConfig: vscode.DebugConfiguration | undefined = undefined; | 117 | const cargo = new Cargo(runnable.cwd || '.', debugOutput); |
105 | let message = ""; | 118 | const executable = await cargo.executableFromArgs(runnable.args); |
106 | |||
107 | const wsLaunchSection = vscode.workspace.getConfiguration("launch"); | ||
108 | const configurations = wsLaunchSection.get<any[]>("configurations") || []; | ||
109 | 119 | ||
110 | const index = configurations.findIndex(c => c.name === config.label); | 120 | // if we are here, there were no compilation errors. |
111 | if (-1 !== index) { | 121 | return executable; |
112 | debugConfig = configurations[index]; | 122 | } |
113 | message = " (from launch.json)"; | ||
114 | debugOutput.clear(); | ||
115 | } else { | ||
116 | debugConfig = await getDebugConfiguration(ctx, config); | ||
117 | } | ||
118 | 123 | ||
119 | if (!debugConfig) return false; | 124 | function getLldbDebugConfig(runnable: ra.Runnable, executable: string, sourceFileMap?: Record<string, string>): vscode.DebugConfiguration { |
125 | return { | ||
126 | type: "lldb", | ||
127 | request: "launch", | ||
128 | name: runnable.label, | ||
129 | program: executable, | ||
130 | args: runnable.extraArgs, | ||
131 | cwd: runnable.cwd, | ||
132 | sourceMap: sourceFileMap, | ||
133 | sourceLanguages: ["rust"] | ||
134 | }; | ||
135 | } | ||
120 | 136 | ||
121 | debugOutput.appendLine(`Launching debug configuration${message}:`); | 137 | function getCppvsDebugConfig(runnable: ra.Runnable, executable: string, sourceFileMap?: Record<string, string>): vscode.DebugConfiguration { |
122 | debugOutput.appendLine(JSON.stringify(debugConfig, null, 2)); | 138 | return { |
123 | return vscode.debug.startDebugging(undefined, debugConfig); | 139 | type: (os.platform() === "win32") ? "cppvsdbg" : "cppdbg", |
140 | request: "launch", | ||
141 | name: runnable.label, | ||
142 | program: executable, | ||
143 | args: runnable.extraArgs, | ||
144 | cwd: runnable.cwd, | ||
145 | sourceFileMap: sourceFileMap, | ||
146 | }; | ||
124 | } | 147 | } |
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'; | |||
3 | import * as ra from './lsp_ext'; | 3 | import * as ra from './lsp_ext'; |
4 | import * as toolchain from "./toolchain"; | 4 | import * as toolchain from "./toolchain"; |
5 | 5 | ||
6 | import { Ctx, Cmd } from './ctx'; | 6 | import { Ctx } from './ctx'; |
7 | import { startDebugSession, getDebugConfiguration } from './debug'; | 7 | import { makeDebugConfig } from './debug'; |
8 | 8 | ||
9 | const quickPickButtons = [{ iconPath: new vscode.ThemeIcon("save"), tooltip: "Save as a launch.json configurtation." }]; | 9 | const 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 | ||
87 | export 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 | |||
104 | export 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 | |||
117 | export function debugSingle(ctx: Ctx): Cmd { | ||
118 | return async (config: ra.Runnable) => { | ||
119 | await startDebugSession(ctx, config); | ||
120 | }; | ||
121 | } | ||
122 | |||
123 | async 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 | |||
146 | export 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 | |||
155 | export class RunnableQuickPick implements vscode.QuickPickItem { | 87 | export class RunnableQuickPick implements vscode.QuickPickItem { |
156 | public label: string; | 88 | public label: string; |
157 | public description?: string | undefined; | 89 | public description?: string | undefined; |