1
- import type { QuickInputButton } from 'vscode' ;
1
+ import type { QuickInputButton , QuickPick } from 'vscode' ;
2
2
import { commands , Uri } from 'vscode' ;
3
3
import { getAvatarUri } from '../../avatars' ;
4
4
import type {
@@ -88,6 +88,8 @@ export interface FocusItemQuickPickItem extends QuickPickItemOfT<FocusItem> {
88
88
89
89
interface Context {
90
90
items : FocusItem [ ] ;
91
+ itemsError ?: Error ;
92
+
91
93
title : string ;
92
94
collapsed : Map < FocusGroup , boolean > ;
93
95
telemetryContext : LaunchpadTelemetryContext | undefined ;
@@ -192,6 +194,7 @@ export class FocusCommand extends QuickCommand<State> {
192
194
193
195
const context : Context = {
194
196
items : [ ] ,
197
+ itemsError : undefined ,
195
198
title : this . title ,
196
199
collapsed : collapsed ,
197
200
telemetryContext : this . telemetryContext ,
@@ -412,13 +415,48 @@ export class FocusCommand extends QuickCommand<State> {
412
415
return items ;
413
416
} ;
414
417
415
- const items = getItems ( context . items ) ;
418
+ function getItemsAndPlaceholder ( ) {
419
+ if ( context . itemsError != null ) {
420
+ return {
421
+ placeholder : `Unable to load items (${ String ( context . itemsError ) } )` ,
422
+ items : [ createDirectiveQuickPickItem ( Directive . Cancel , undefined , { label : 'OK' } ) ] ,
423
+ } ;
424
+ }
425
+
426
+ if ( ! context . items . length ) {
427
+ return {
428
+ placeholder : 'All done! Take a vacation' ,
429
+ items : [ createDirectiveQuickPickItem ( Directive . Cancel , undefined , { label : 'OK' } ) ] ,
430
+ } ;
431
+ }
432
+
433
+ return {
434
+ placeholder : 'Choose an item to focus on' ,
435
+ items : getItems ( context . items ) ,
436
+ } ;
437
+ }
438
+
439
+ const updateItems = async ( quickpick : QuickPick < FocusItemQuickPickItem | DirectiveQuickPickItem > ) => {
440
+ quickpick . busy = true ;
441
+
442
+ try {
443
+ await updateContextItems ( this . container , context , { force : true } ) ;
444
+
445
+ const { items, placeholder } = getItemsAndPlaceholder ( ) ;
446
+ quickpick . placeholder = placeholder ;
447
+ quickpick . items = items ;
448
+ } finally {
449
+ quickpick . busy = false ;
450
+ }
451
+ } ;
452
+
453
+ const { items, placeholder } = getItemsAndPlaceholder ( ) ;
416
454
417
455
const step = createPickStep ( {
418
456
title : context . title ,
419
- placeholder : ! items . length ? 'All done! Take a vacation' : 'Choose an item to focus on' ,
457
+ placeholder : placeholder ,
420
458
matchOnDetail : true ,
421
- items : ! items . length ? [ createDirectiveQuickPickItem ( Directive . Cancel , undefined , { label : 'OK' } ) ] : items ,
459
+ items : items ,
422
460
buttons : [
423
461
FeedbackQuickInputButton ,
424
462
OpenInEditorQuickInputButton ,
@@ -438,19 +476,7 @@ export class FocusCommand extends QuickCommand<State> {
438
476
void executeCommand ( Commands . ShowFocusPage ) ;
439
477
break ;
440
478
case RefreshQuickInputButton :
441
- quickpick . busy = true ;
442
-
443
- try {
444
- await updateContextItems ( this . container , context , { force : true } ) ;
445
- const items = getItems ( context . items ) ;
446
-
447
- quickpick . placeholder = ! items . length
448
- ? 'All done! Take a vacation'
449
- : 'Choose an item to focus on' ;
450
- quickpick . items = items ;
451
- } finally {
452
- quickpick . busy = false ;
453
- }
479
+ await updateItems ( quickpick ) ;
454
480
break ;
455
481
}
456
482
} ,
@@ -482,17 +508,7 @@ export class FocusCommand extends QuickCommand<State> {
482
508
}
483
509
484
510
this . sendItemActionTelemetry ( button , item , group , context ) ;
485
- quickpick . busy = true ;
486
-
487
- try {
488
- await updateContextItems ( this . container , context ) ;
489
- const items = getItems ( context . items ) ;
490
-
491
- quickpick . placeholder = ! items . length ? 'All done! Take a vacation' : 'Choose an item to focus on' ;
492
- quickpick . items = items ;
493
- } finally {
494
- quickpick . busy = false ;
495
- }
511
+ await updateItems ( quickpick ) ;
496
512
} ,
497
513
} ) ;
498
514
@@ -972,7 +988,13 @@ export class FocusCommand extends QuickCommand<State> {
972
988
}
973
989
974
990
async function updateContextItems ( container : Container , context : Context , options ?: { force ?: boolean } ) {
975
- context . items = await container . focus . getCategorizedItems ( options ) ;
991
+ try {
992
+ context . items = await container . focus . getCategorizedItems ( options ) ;
993
+ context . itemsError = undefined ;
994
+ } catch ( ex ) {
995
+ context . items = [ ] ;
996
+ context . itemsError = ex ;
997
+ }
976
998
if ( container . telemetry . enabled ) {
977
999
updateTelemetryContext ( context ) ;
978
1000
}
0 commit comments