@@ -49,9 +49,9 @@ import {
49
49
import type {
50
50
FocusAction ,
51
51
FocusActionCategory ,
52
+ FocusCategorizedResult ,
52
53
FocusGroup ,
53
54
FocusItem ,
54
- FocusItemsWithDurations ,
55
55
FocusTargetAction ,
56
56
} from './focusProvider' ;
57
57
import {
@@ -94,8 +94,7 @@ export interface FocusItemQuickPickItem extends QuickPickItemOfT<FocusItem> {
94
94
}
95
95
96
96
interface Context {
97
- items : FocusItemsWithDurations ;
98
- itemsError ?: Error ;
97
+ result : FocusCategorizedResult ;
99
98
100
99
title : string ;
101
100
collapsed : Map < FocusGroup , boolean > ;
@@ -200,15 +199,7 @@ export class FocusCommand extends QuickCommand<State> {
200
199
}
201
200
202
201
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 : [ ] } ,
212
203
title : this . title ,
213
204
collapsed : collapsed ,
214
205
telemetryContext : this . telemetryContext ,
@@ -336,11 +327,11 @@ export class FocusCommand extends QuickCommand<State> {
336
327
context : Context ,
337
328
{ picked, selectTopItem } : { picked ?: string ; selectTopItem ?: boolean } ,
338
329
) : StepResultGenerator < GroupedFocusItem > {
339
- const getItems = ( categorizedItems : FocusItemsWithDurations ) => {
330
+ const getItems = ( result : FocusCategorizedResult ) => {
340
331
const items : ( FocusItemQuickPickItem | DirectiveQuickPickItem ) [ ] = [ ] ;
341
332
342
- if ( categorizedItems . items ?. length ) {
343
- const uiGroups = groupAndSortFocusItems ( categorizedItems . items ) ;
333
+ if ( result . items ?. length ) {
334
+ const uiGroups = groupAndSortFocusItems ( result . items ) ;
344
335
const topItem : FocusItem | undefined =
345
336
! selectTopItem || picked != null
346
337
? undefined
@@ -429,14 +420,14 @@ export class FocusCommand extends QuickCommand<State> {
429
420
} ;
430
421
431
422
function getItemsAndPlaceholder ( ) {
432
- if ( context . itemsError != null ) {
423
+ if ( context . result . error != null ) {
433
424
return {
434
- placeholder : `Unable to load items (${ String ( context . itemsError ) } )` ,
425
+ placeholder : `Unable to load items (${ String ( context . result . error ) } )` ,
435
426
items : [ createDirectiveQuickPickItem ( Directive . Cancel , undefined , { label : 'OK' } ) ] ,
436
427
} ;
437
428
}
438
429
439
- if ( ! context . items . items . length ) {
430
+ if ( ! context . result . items . length ) {
440
431
return {
441
432
placeholder : 'All done! Take a vacation' ,
442
433
items : [ createDirectiveQuickPickItem ( Directive . Cancel , undefined , { label : 'OK' } ) ] ,
@@ -445,7 +436,7 @@ export class FocusCommand extends QuickCommand<State> {
445
436
446
437
return {
447
438
placeholder : 'Choose an item to focus on' ,
448
- items : getItems ( context . items ) ,
439
+ items : getItems ( context . result ) ,
449
440
} ;
450
441
}
451
442
@@ -1012,15 +1003,7 @@ export class FocusCommand extends QuickCommand<State> {
1012
1003
}
1013
1004
1014
1005
async 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 ) ;
1024
1007
if ( container . telemetry . enabled ) {
1025
1008
updateTelemetryContext ( context ) ;
1026
1009
}
@@ -1029,20 +1012,28 @@ async function updateContextItems(container: Container, context: Context, option
1029
1012
function updateTelemetryContext ( context : Context ) {
1030
1013
if ( context . telemetryContext == null ) return ;
1031
1014
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
+ } ;
1042
1032
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
+ }
1046
1037
}
1047
1038
1048
1039
context . telemetryContext = updatedContext ;
0 commit comments