@@ -3,7 +3,7 @@ import { MenuModelRegistry } from '@theia/core/lib/common/menu/menu-model-regist
3
3
import { nls } from '@theia/core/lib/common/nls' ;
4
4
import { MaybePromise } from '@theia/core/lib/common/types' ;
5
5
import { inject , injectable } from '@theia/core/shared/inversify' ;
6
- import { noBoardSelected , noSketchOpened } from '../../common/nls' ;
6
+ import { noBoardSelected } from '../../common/nls' ;
7
7
import {
8
8
BoardDetails ,
9
9
BoardIdentifier ,
@@ -193,24 +193,30 @@ export class Debug extends SketchContribution {
193
193
}
194
194
}
195
195
196
- private async isDebugEnabled ( ) : Promise < void > {
197
- const sketch = this . sketchServiceClient . tryGetCurrentSketch ( ) ;
198
- const board = this . boardsServiceProvider . boardsConfig . selectedBoard ;
199
- await isDebugEnabled (
200
- sketch ,
196
+ private async isDebugEnabled (
197
+ board : BoardIdentifier | undefined = this . boardsServiceProvider . boardsConfig
198
+ . selectedBoard
199
+ ) : Promise < string > {
200
+ const debugFqbn = await isDebugEnabled (
201
201
board ,
202
202
( fqbn ) => this . boardService . getBoardDetails ( { fqbn } ) ,
203
203
( fqbn ) => this . boardsDataStore . getData ( fqbn ) ,
204
204
( fqbn ) => this . boardsDataStore . appendConfigToFqbn ( fqbn ) ,
205
- ( params ) => this . boardService . checkDebugEnabled ( params ) ,
206
- ( reason , sketch ) => this . isSketchNotVerifiedError ( reason , sketch )
205
+ ( params ) => this . boardService . checkDebugEnabled ( params )
207
206
) ;
207
+ return debugFqbn ;
208
208
}
209
209
210
210
private async startDebug (
211
211
board : BoardIdentifier | undefined = this . boardsServiceProvider . boardsConfig
212
- . selectedBoard
212
+ . selectedBoard ,
213
+ sketch :
214
+ | CurrentSketch
215
+ | undefined = this . sketchServiceClient . tryGetCurrentSketch ( )
213
216
) : Promise < StartDebugResult > {
217
+ if ( ! CurrentSketch . isValid ( sketch ) ) {
218
+ return false ;
219
+ }
214
220
const params = await this . createStartDebugParams ( board ) ;
215
221
if ( ! params ) {
216
222
return false ;
@@ -220,6 +226,20 @@ export class Debug extends SketchContribution {
220
226
const result = await this . debug ( params ) ;
221
227
return Boolean ( result ) ;
222
228
} catch ( err ) {
229
+ if ( await this . isSketchNotVerifiedError ( err , sketch ) ) {
230
+ const yes = nls . localize ( 'vscode/extensionsUtils/yes' , 'Yes' ) ;
231
+ const answer = await this . messageService . error (
232
+ sketchIsNotCompiled ( sketch . name ) ,
233
+ yes
234
+ ) ;
235
+ if ( answer === yes ) {
236
+ this . commandService . executeCommand ( 'arduino-verify-sketch' ) ;
237
+ }
238
+ } else {
239
+ this . messageService . error (
240
+ err instanceof Error ? err . message : String ( err )
241
+ ) ;
242
+ }
223
243
console . error ( err ) ;
224
244
this . messageService . error (
225
245
err instanceof Error ? err . message : String ( err )
@@ -272,13 +292,20 @@ export class Debug extends SketchContribution {
272
292
if ( ! board || ! board . fqbn ) {
273
293
return undefined ;
274
294
}
295
+ let debugFqbn : string | undefined = undefined ;
296
+ try {
297
+ debugFqbn = await this . isDebugEnabled ( board ) ;
298
+ } catch { }
299
+ if ( ! debugFqbn ) {
300
+ return undefined ;
301
+ }
275
302
const [ sketch , executables , boardsData ] = await Promise . all ( [
276
303
this . sketchServiceClient . currentSketch ( ) ,
277
304
this . executableService . list ( ) ,
278
305
this . boardsDataStore . getData ( board . fqbn ) ,
279
306
] ) ;
280
307
if ( ! CurrentSketch . isValid ( sketch ) ) {
281
- return ;
308
+ return undefined ;
282
309
}
283
310
const ideTempFolderUri = await this . sketchesService . getIdeTempFolderUri (
284
311
sketch
@@ -289,7 +316,7 @@ export class Debug extends SketchContribution {
289
316
this . fileService . fsPath ( new URI ( ideTempFolderUri ) ) ,
290
317
] ) ;
291
318
return {
292
- board : { fqbn : board . fqbn , name : board . name } ,
319
+ board : { fqbn : debugFqbn , name : board . name } ,
293
320
cliPath,
294
321
sketchPath,
295
322
launchConfigsDirPath,
@@ -329,20 +356,12 @@ export namespace Debug {
329
356
* (non-API)
330
357
*/
331
358
export async function isDebugEnabled (
332
- sketch : CurrentSketch | undefined ,
333
359
board : BoardIdentifier | undefined ,
334
360
getDetails : ( fqbn : string ) => MaybePromise < BoardDetails | undefined > ,
335
361
getData : ( fqbn : string ) => MaybePromise < BoardsDataStore . Data > ,
336
362
appendConfigToFqbn : ( fqbn : string ) => MaybePromise < string | undefined > ,
337
- checkDebugEnabled : ( params : CheckDebugEnabledParams ) => MaybePromise < void > ,
338
- isSketchNotVerifiedError : (
339
- err : unknown ,
340
- sketchRef : SketchRef
341
- ) => MaybePromise < boolean >
342
- ) : Promise < void > {
343
- if ( ! CurrentSketch . isValid ( sketch ) ) {
344
- throw new Error ( noSketchOpened ) ;
345
- }
363
+ checkDebugEnabled : ( params : CheckDebugEnabledParams ) => MaybePromise < string >
364
+ ) : Promise < string > {
346
365
if ( ! board ) {
347
366
throw new Error ( noBoardSelected ) ;
348
367
}
@@ -369,15 +388,11 @@ export async function isDebugEnabled(
369
388
const params = {
370
389
fqbn : fqbnWithConfig ,
371
390
programmer : data . selectedProgrammer . id ,
372
- sketchUri : sketch . uri ,
373
391
} ;
374
392
try {
375
- await checkDebugEnabled ( params ) ;
393
+ const debugFqbn = await checkDebugEnabled ( params ) ;
394
+ return debugFqbn ;
376
395
} catch ( err ) {
377
- const sketchNotVerified = await isSketchNotVerifiedError ( err , sketch ) ;
378
- if ( sketchNotVerified ) {
379
- throw new Error ( sketchIsNotCompiled ( sketch . name ) ) ;
380
- }
381
396
throw new Error ( debuggingNotSupported ( board . name ) ) ;
382
397
}
383
398
}
@@ -388,7 +403,7 @@ export async function isDebugEnabled(
388
403
export function sketchIsNotCompiled ( sketchName : string ) : string {
389
404
return nls . localize (
390
405
'arduino/debug/sketchIsNotCompiled' ,
391
- "Sketch '{0}' must be verified before starting a debug session" ,
406
+ "Sketch '{0}' must be verified before starting a debug session. Please verify the sketch and start debugging again. Do you want to verify the sketch now? " ,
392
407
sketchName
393
408
) ;
394
409
}
0 commit comments