1- import type { QuickInputButton } from 'vscode' ;
1+ import type { QuickInputButton , QuickPick } from 'vscode' ;
22import { commands , Uri } from 'vscode' ;
33import { getAvatarUri } from '../../avatars' ;
44import type {
@@ -88,6 +88,8 @@ export interface FocusItemQuickPickItem extends QuickPickItemOfT<FocusItem> {
8888
8989interface Context {
9090 items : FocusItem [ ] ;
91+ itemsError ?: Error ;
92+
9193 title : string ;
9294 collapsed : Map < FocusGroup , boolean > ;
9395 telemetryContext : LaunchpadTelemetryContext | undefined ;
@@ -192,6 +194,7 @@ export class FocusCommand extends QuickCommand<State> {
192194
193195 const context : Context = {
194196 items : [ ] ,
197+ itemsError : undefined ,
195198 title : this . title ,
196199 collapsed : collapsed ,
197200 telemetryContext : this . telemetryContext ,
@@ -412,13 +415,48 @@ export class FocusCommand extends QuickCommand<State> {
412415 return items ;
413416 } ;
414417
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 ( ) ;
416454
417455 const step = createPickStep ( {
418456 title : context . title ,
419- placeholder : ! items . length ? 'All done! Take a vacation' : 'Choose an item to focus on' ,
457+ placeholder : placeholder ,
420458 matchOnDetail : true ,
421- items : ! items . length ? [ createDirectiveQuickPickItem ( Directive . Cancel , undefined , { label : 'OK' } ) ] : items ,
459+ items : items ,
422460 buttons : [
423461 FeedbackQuickInputButton ,
424462 OpenInEditorQuickInputButton ,
@@ -438,19 +476,7 @@ export class FocusCommand extends QuickCommand<State> {
438476 void executeCommand ( Commands . ShowFocusPage ) ;
439477 break ;
440478 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 ) ;
454480 break ;
455481 }
456482 } ,
@@ -482,17 +508,7 @@ export class FocusCommand extends QuickCommand<State> {
482508 }
483509
484510 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 ) ;
496512 } ,
497513 } ) ;
498514
@@ -972,7 +988,13 @@ export class FocusCommand extends QuickCommand<State> {
972988}
973989
974990async 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+ }
976998 if ( container . telemetry . enabled ) {
977999 updateTelemetryContext ( context ) ;
9781000 }
0 commit comments