@@ -49,9 +49,9 @@ import {
4949import type {
5050 FocusAction ,
5151 FocusActionCategory ,
52+ FocusCategorizedResult ,
5253 FocusGroup ,
5354 FocusItem ,
54- FocusItemsWithDurations ,
5555 FocusTargetAction ,
5656} from './focusProvider' ;
5757import {
@@ -94,8 +94,7 @@ export interface FocusItemQuickPickItem extends QuickPickItemOfT<FocusItem> {
9494}
9595
9696interface Context {
97- items : FocusItemsWithDurations ;
98- itemsError ?: Error ;
97+ result : FocusCategorizedResult ;
9998
10099 title : string ;
101100 collapsed : Map < FocusGroup , boolean > ;
@@ -200,15 +199,7 @@ export class FocusCommand extends QuickCommand<State> {
200199 }
201200
202201 const context : Context = {
203- items : {
204- items : [ ] ,
205- timings : {
206- prs : undefined ,
207- codeSuggestionCounts : undefined ,
208- enrichedItems : undefined ,
209- } ,
210- } ,
211- itemsError : undefined ,
202+ result : { items : [ ] } ,
212203 title : this . title ,
213204 collapsed : collapsed ,
214205 telemetryContext : this . telemetryContext ,
@@ -336,11 +327,11 @@ export class FocusCommand extends QuickCommand<State> {
336327 context : Context ,
337328 { picked, selectTopItem } : { picked ?: string ; selectTopItem ?: boolean } ,
338329 ) : StepResultGenerator < GroupedFocusItem > {
339- const getItems = ( categorizedItems : FocusItemsWithDurations ) => {
330+ const getItems = ( result : FocusCategorizedResult ) => {
340331 const items : ( FocusItemQuickPickItem | DirectiveQuickPickItem ) [ ] = [ ] ;
341332
342- if ( categorizedItems . items ?. length ) {
343- const uiGroups = groupAndSortFocusItems ( categorizedItems . items ) ;
333+ if ( result . items ?. length ) {
334+ const uiGroups = groupAndSortFocusItems ( result . items ) ;
344335 const topItem : FocusItem | undefined =
345336 ! selectTopItem || picked != null
346337 ? undefined
@@ -429,14 +420,14 @@ export class FocusCommand extends QuickCommand<State> {
429420 } ;
430421
431422 function getItemsAndPlaceholder ( ) {
432- if ( context . itemsError != null ) {
423+ if ( context . result . error != null ) {
433424 return {
434- placeholder : `Unable to load items (${ String ( context . itemsError ) } )` ,
425+ placeholder : `Unable to load items (${ String ( context . result . error ) } )` ,
435426 items : [ createDirectiveQuickPickItem ( Directive . Cancel , undefined , { label : 'OK' } ) ] ,
436427 } ;
437428 }
438429
439- if ( ! context . items . items . length ) {
430+ if ( ! context . result . items . length ) {
440431 return {
441432 placeholder : 'All done! Take a vacation' ,
442433 items : [ createDirectiveQuickPickItem ( Directive . Cancel , undefined , { label : 'OK' } ) ] ,
@@ -445,7 +436,7 @@ export class FocusCommand extends QuickCommand<State> {
445436
446437 return {
447438 placeholder : 'Choose an item to focus on' ,
448- items : getItems ( context . items ) ,
439+ items : getItems ( context . result ) ,
449440 } ;
450441 }
451442
@@ -1012,15 +1003,7 @@ export class FocusCommand extends QuickCommand<State> {
10121003}
10131004
10141005async function updateContextItems ( container : Container , context : Context , options ?: { force ?: boolean } ) {
1015- try {
1016- context . items = await container . focus . getCategorizedItems ( options ) ;
1017- context . itemsError = undefined ;
1018- } catch ( ex ) {
1019- context . items = {
1020- items : [ ] ,
1021- } ;
1022- context . itemsError = ex ;
1023- }
1006+ context . result = await container . focus . getCategorizedItems ( options ) ;
10241007 if ( container . telemetry . enabled ) {
10251008 updateTelemetryContext ( context ) ;
10261009 }
@@ -1029,20 +1012,28 @@ async function updateContextItems(container: Container, context: Context, option
10291012function updateTelemetryContext ( context : Context ) {
10301013 if ( context . telemetryContext == null ) return ;
10311014
1032- const grouped = countFocusItemGroups ( context . items . items ) ;
1033-
1034- const updatedContext : NonNullable < ( typeof context ) [ 'telemetryContext' ] > = {
1035- ...context . telemetryContext ,
1036- 'items.count' : context . items . items . length ,
1037- 'groups.count' : grouped . size ,
1038- 'items.timings.prs' : context . items . timings ?. prs ,
1039- 'items.timings.codeSuggestionCounts' : context . items . timings ?. codeSuggestionCounts ,
1040- 'items.timings.enrichedItems' : context . items . timings ?. enrichedItems ,
1041- } ;
1015+ let updatedContext : NonNullable < ( typeof context ) [ 'telemetryContext' ] > ;
1016+ if ( context . result . error != null ) {
1017+ updatedContext = {
1018+ ...context . telemetryContext ,
1019+ 'items.error' : String ( context . result . error ) ,
1020+ } ;
1021+ } else {
1022+ const grouped = countFocusItemGroups ( context . result . items ) ;
1023+
1024+ updatedContext = {
1025+ ...context . telemetryContext ,
1026+ 'items.count' : context . result . items . length ,
1027+ 'items.timings.prs' : context . result . timings ?. prs ,
1028+ 'items.timings.codeSuggestionCounts' : context . result . timings ?. codeSuggestionCounts ,
1029+ 'items.timings.enrichedItems' : context . result . timings ?. enrichedItems ,
1030+ 'groups.count' : grouped . size ,
1031+ } ;
10421032
1043- for ( const [ group , count ] of grouped ) {
1044- updatedContext [ `groups.${ group } .count` ] = count ;
1045- updatedContext [ `groups.${ group } .collapsed` ] = context . collapsed . get ( group ) ;
1033+ for ( const [ group , count ] of grouped ) {
1034+ updatedContext [ `groups.${ group } .count` ] = count ;
1035+ updatedContext [ `groups.${ group } .collapsed` ] = context . collapsed . get ( group ) ;
1036+ }
10461037 }
10471038
10481039 context . telemetryContext = updatedContext ;
0 commit comments