Skip to content

Commit 75ac8d3

Browse files
committed
Offer option to create launch configurations for all Mains
1 parent 3f3facd commit 75ac8d3

File tree

3 files changed

+44
-19
lines changed

3 files changed

+44
-19
lines changed

integration/vscode/ada/src/commands.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
import * as vscode from 'vscode';
22
import { SymbolKind } from 'vscode';
33
import { ContextClients } from './clients';
4-
import { AdaDebugConfigProvider } from './debugConfigProvider';
4+
import { getOrAskForProgram } from './debugConfigProvider';
55
import { mainLogChannel } from './extension';
66
import { getEnclosingSymbol } from './gnatTaskProvider';
77

8-
export function registerCommands(
9-
context: vscode.ExtensionContext,
10-
clients: ContextClients,
11-
debug: AdaDebugConfigProvider
12-
) {
8+
export function registerCommands(context: vscode.ExtensionContext, clients: ContextClients) {
139
context.subscriptions.push(
1410
vscode.commands.registerCommand('ada.otherFile', clients.otherFileHandler)
1511
);
@@ -34,7 +30,7 @@ export function registerCommands(
3430
// configuration snippet that gets offered in the launch.json file.
3531
context.subscriptions.push(
3632
vscode.commands.registerCommand('ada.getOrAskForProgram', async () => {
37-
const p = await debug.getOrAskForProgram();
33+
const p = await getOrAskForProgram();
3834
return p;
3935
})
4036
);

integration/vscode/ada/src/debugConfigProvider.ts

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import assert from 'assert';
2-
import * as path from 'path';
32
import * as vscode from 'vscode';
43
import { contextClients } from './extension';
54
import { getExecutables, getMains, getProjectFile } from './helpers';
@@ -55,12 +54,14 @@ export function initializeDebugging(ctx: vscode.ExtensionContext) {
5554
* Initialize a debug configuration based on 'cppdbg' for the given executable
5655
* if specified. Otherwise the program field includes
5756
* $\{command:ada.getOrAskForProgram\} to prompt the User for an executable to
58-
* debug.
57+
* debug. If `main` is specified, it is simply used in the name of the launch
58+
* configuration.
5959
*
6060
* @param program - the executable to debug (optional)
61+
* @param main - the main source file to be displayed in the configuration label (optional)
6162
* @returns an AdaConfig
6263
*/
63-
function initializeConfig(program?: string): AdaConfig {
64+
function initializeConfig(program?: string, main?: string): AdaConfig {
6465
// TODO it would be nice if this and the package.json configuration snippet
6566
// were the same.
6667
const config: AdaConfig = {
@@ -79,9 +80,13 @@ function initializeConfig(program?: string): AdaConfig {
7980
};
8081

8182
if (program) {
82-
const name = path.basename(program);
83-
config.name = 'Ada: Debug executable - ' + name;
8483
config.program = program;
84+
const name = program.replace('${workspaceFolder}/', '');
85+
config.name = `Ada: Debug executable - ${name}`;
86+
}
87+
88+
if (main) {
89+
config.name = `Ada: Debug main - ${main}`;
8590
}
8691

8792
return config;
@@ -122,18 +127,42 @@ export class AdaDebugConfigProvider implements vscode.DebugConfigurationProvider
122127
quickpick.push({
123128
label: vscode.workspace.asRelativePath(main),
124129
description: 'Generate the associated launch configuration',
125-
execPath: vscode.workspace.asRelativePath(exec),
130+
execRelPath: vscode.workspace.asRelativePath(exec),
126131
});
127132
}
133+
134+
const generateAll = {
135+
label: 'All of the above',
136+
description: 'Generate launch configurations for each Main file of the project',
137+
execRelPath: '',
138+
};
139+
if (mains.length > 1) {
140+
quickpick.push(generateAll);
141+
}
142+
128143
const selectedProgram = await vscode.window.showQuickPick(quickpick, {
129-
placeHolder: 'Select a main to create a launch configuration',
144+
placeHolder: 'Select a main file to create a launch configuration',
130145
});
131-
if (selectedProgram) {
146+
147+
if (selectedProgram == generateAll) {
148+
void vscode.window.showInformationMessage('Hello');
149+
for (let i = 0; i < mains.length; i++) {
150+
const main = mains[i];
151+
const exec = execs[i];
152+
configs.push(
153+
initializeConfig(
154+
`\${workspaceFolder}/${vscode.workspace.asRelativePath(exec)}`,
155+
vscode.workspace.asRelativePath(main)
156+
)
157+
);
158+
}
159+
} else if (selectedProgram) {
132160
// The cppdbg debug configuration exepects the executable to be
133161
// a full path rather than a path relative to the specified
134162
// cwd. That is why we include ${workspaceFolder}.
135163
const configuration = initializeConfig(
136-
`\${workspaceFolder}/${selectedProgram.execPath}`
164+
`\${workspaceFolder}/${selectedProgram.execRelPath}`,
165+
selectedProgram.label
137166
);
138167
configs.push(configuration);
139168
} else {
@@ -220,7 +249,7 @@ const setupCmd = [
220249
* @returns the path of the executable to debug *relative to the workspace*,
221250
* or *undefined* if no selection was made.
222251
*/
223-
async function getOrAskForProgram(): Promise<string | undefined> {
252+
export async function getOrAskForProgram(): Promise<string | undefined> {
224253
const mains = await getMains(contextClients.adaClient);
225254
const execs = await getExecutables(contextClients.adaClient);
226255

integration/vscode/ada/src/extension.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
7878

7979
await Promise.all([contextClients.adaClient.onReady(), contextClients.gprClient.onReady()]);
8080

81-
const adaDebugConfigProvider = initializeDebugging(context);
81+
initializeDebugging(context);
8282

83-
registerCommands(context, contextClients, adaDebugConfigProvider);
83+
registerCommands(context, contextClients);
8484

8585
mainLogChannel.appendLine('Started Ada extension');
8686
}

0 commit comments

Comments
 (0)