11import assert from 'assert' ;
2- import * as path from 'path' ;
32import * as vscode from 'vscode' ;
43import { contextClients } from './extension' ;
54import { 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
0 commit comments