1
1
import assert from 'assert' ;
2
- import * as path from 'path' ;
3
2
import * as vscode from 'vscode' ;
4
3
import { contextClients } from './extension' ;
5
4
import { getExecutables , getMains , getProjectFile } from './helpers' ;
@@ -55,12 +54,14 @@ export function initializeDebugging(ctx: vscode.ExtensionContext) {
55
54
* Initialize a debug configuration based on 'cppdbg' for the given executable
56
55
* if specified. Otherwise the program field includes
57
56
* $\{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.
59
59
*
60
60
* @param program - the executable to debug (optional)
61
+ * @param main - the main source file to be displayed in the configuration label (optional)
61
62
* @returns an AdaConfig
62
63
*/
63
- function initializeConfig ( program ?: string ) : AdaConfig {
64
+ function initializeConfig ( program ?: string , main ?: string ) : AdaConfig {
64
65
// TODO it would be nice if this and the package.json configuration snippet
65
66
// were the same.
66
67
const config : AdaConfig = {
@@ -79,9 +80,13 @@ function initializeConfig(program?: string): AdaConfig {
79
80
} ;
80
81
81
82
if ( program ) {
82
- const name = path . basename ( program ) ;
83
- config . name = 'Ada: Debug executable - ' + name ;
84
83
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 } ` ;
85
90
}
86
91
87
92
return config ;
@@ -122,18 +127,42 @@ export class AdaDebugConfigProvider implements vscode.DebugConfigurationProvider
122
127
quickpick . push ( {
123
128
label : vscode . workspace . asRelativePath ( main ) ,
124
129
description : 'Generate the associated launch configuration' ,
125
- execPath : vscode . workspace . asRelativePath ( exec ) ,
130
+ execRelPath : vscode . workspace . asRelativePath ( exec ) ,
126
131
} ) ;
127
132
}
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
+
128
143
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' ,
130
145
} ) ;
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 ) {
132
160
// The cppdbg debug configuration exepects the executable to be
133
161
// a full path rather than a path relative to the specified
134
162
// cwd. That is why we include ${workspaceFolder}.
135
163
const configuration = initializeConfig (
136
- `\${workspaceFolder}/${ selectedProgram . execPath } `
164
+ `\${workspaceFolder}/${ selectedProgram . execRelPath } ` ,
165
+ selectedProgram . label
137
166
) ;
138
167
configs . push ( configuration ) ;
139
168
} else {
@@ -220,7 +249,7 @@ const setupCmd = [
220
249
* @returns the path of the executable to debug *relative to the workspace*,
221
250
* or *undefined* if no selection was made.
222
251
*/
223
- async function getOrAskForProgram ( ) : Promise < string | undefined > {
252
+ export async function getOrAskForProgram ( ) : Promise < string | undefined > {
224
253
const mains = await getMains ( contextClients . adaClient ) ;
225
254
const execs = await getExecutables ( contextClients . adaClient ) ;
226
255
0 commit comments