@@ -50,6 +50,7 @@ import { getScopedCounter } from '../../system/counter';
5050import { fromNow } from '../../system/date' ;
5151import { some } from '../../system/iterable' ;
5252import { interpolate , pluralize } from '../../system/string' ;
53+ import { createAsyncDebouncer } from '../../system/vscode/asyncDebouncer' ;
5354import { executeCommand } from '../../system/vscode/command' ;
5455import { configuration } from '../../system/vscode/configuration' ;
5556import { openUrl } from '../../system/vscode/utils' ;
@@ -149,6 +150,7 @@ const instanceCounter = getScopedCounter();
149150const defaultCollapsedGroups : LaunchpadGroup [ ] = [ 'draft' , 'other' , 'snoozed' ] ;
150151
151152export class LaunchpadCommand extends QuickCommand < State > {
153+ private readonly updateItemsDebouncer = createAsyncDebouncer ( 500 ) ;
152154 private readonly source : Source ;
153155 private readonly telemetryContext : LaunchpadTelemetryContext | undefined ;
154156
@@ -458,7 +460,7 @@ export class LaunchpadCommand extends QuickCommand<State> {
458460 } ;
459461 } ;
460462
461- const getItems = ( result : LaunchpadCategorizedResult ) => {
463+ const getItems = ( result : LaunchpadCategorizedResult , treatAllGroupAsExpanded ?: boolean ) => {
462464 const items : ( LaunchpadItemQuickPickItem | DirectiveQuickPickItem | ConnectMoreIntegrationsItem ) [ ] = [ ] ;
463465
464466 if ( result . items ?. length ) {
@@ -475,7 +477,7 @@ export class LaunchpadCommand extends QuickCommand<State> {
475477
476478 items . push ( ...buildGroupHeading ( ui , groupItems . length ) ) ;
477479
478- if ( context . collapsed . get ( ui ) ) continue ;
480+ if ( ! treatAllGroupAsExpanded && context . collapsed . get ( ui ) ) continue ;
479481
480482 items . push ( ...groupItems . map ( i => buildLaunchpadQuickPickItem ( i , ui , topItem ) ) ) ;
481483 }
@@ -484,7 +486,7 @@ export class LaunchpadCommand extends QuickCommand<State> {
484486 return items ;
485487 } ;
486488
487- function getItemsAndPlaceholder ( ) {
489+ function getItemsAndPlaceholder ( treatAllGroupAsExpanded ?: boolean ) {
488490 if ( context . result . error != null ) {
489491 return {
490492 placeholder : `Unable to load items (${
@@ -507,7 +509,7 @@ export class LaunchpadCommand extends QuickCommand<State> {
507509
508510 return {
509511 placeholder : 'Choose an item to focus on' ,
510- items : getItems ( context . result ) ,
512+ items : getItems ( context . result , treatAllGroupAsExpanded ) ,
511513 } ;
512514 }
513515
@@ -516,13 +518,16 @@ export class LaunchpadCommand extends QuickCommand<State> {
516518 search ?: string ,
517519 ) => {
518520 quickpick . busy = true ;
519-
520521 try {
521- await updateContextItems ( this . container , context , { force : true , search : search } ) ;
522-
523- const { items, placeholder } = getItemsAndPlaceholder ( ) ;
524- quickpick . placeholder = placeholder ;
525- quickpick . items = items ;
522+ await this . updateItemsDebouncer ( async cancellationToken => {
523+ await updateContextItems ( this . container , context , { force : true , search : search } ) ;
524+ if ( cancellationToken . isCancellationRequested ) {
525+ return ;
526+ }
527+ const { items, placeholder } = getItemsAndPlaceholder ( Boolean ( search ) ) ;
528+ quickpick . placeholder = placeholder ;
529+ quickpick . items = items ;
530+ } ) ;
526531 } finally {
527532 quickpick . busy = false ;
528533 }
@@ -591,6 +596,7 @@ export class LaunchpadCommand extends QuickCommand<State> {
591596 }
592597 // We have found an item that matches to the URL.
593598 // Now it will be displayed as the found item and we exit this function now without sending any requests to API:
599+ this . updateItemsDebouncer . cancel ( ) ;
594600 return true ;
595601 }
596602 // Nothing is found above, so let's perform search in the API:
@@ -599,7 +605,7 @@ export class LaunchpadCommand extends QuickCommand<State> {
599605 groupsHidden = true ;
600606 }
601607 }
602-
608+ this . updateItemsDebouncer . cancel ( ) ;
603609 return true ;
604610 } ,
605611 onDidClickButton : async ( quickpick , button ) => {
@@ -1340,7 +1346,7 @@ async function updateContextItems(
13401346 options ?: { force ?: boolean ; search ?: string } ,
13411347) {
13421348 const result = await container . launchpad . getCategorizedItems ( options ) ;
1343- if ( options ?. search != null ) {
1349+ if ( options ?. search ) {
13441350 context . result = container . launchpad . mergeSearchedCategorizedItems ( context . result , result ) ;
13451351 } else {
13461352 context . result = result ;
0 commit comments