@@ -518,6 +518,19 @@ export class LaunchpadCommand extends QuickCommand<State> {
518518 } ;
519519 }
520520
521+ const mergeQuickpickItems = < T extends { item : { id : string } } | object > ( arr : readonly T [ ] , items : T [ ] ) => {
522+ const ids : Set < string > = new Set (
523+ arr . map ( i => 'item' in i && i . item ?. id ) . filter ( id => typeof id === 'string' ) ,
524+ ) ;
525+ const result = [ ...arr ] ;
526+ for ( const item of items ) {
527+ if ( 'item' in item && item . item ?. id && ! ids . has ( item . item . id ) ) {
528+ result . push ( item ) ;
529+ }
530+ }
531+ return result ;
532+ } ;
533+
521534 const updateItems = async (
522535 quickpick : QuickPick < LaunchpadItemQuickPickItem | DirectiveQuickPickItem | ConnectMoreIntegrationsItem > ,
523536 ) => {
@@ -536,7 +549,7 @@ export class LaunchpadCommand extends QuickCommand<State> {
536549 }
537550 const { items, placeholder } = getItemsAndPlaceholder ( Boolean ( search ) ) ;
538551 quickpick . placeholder = placeholder ;
539- quickpick . items = items ;
552+ quickpick . items = search ? mergeQuickpickItems ( quickpick . items , items ) : items ;
540553 } ) ;
541554 } finally {
542555 quickpick . busy = false ;
@@ -577,11 +590,7 @@ export class LaunchpadCommand extends QuickCommand<State> {
577590 quickpick . items =
578591 updated && quickpick . items === consideredItems ? [ ...consideredItems ] : consideredItems ;
579592
580- const activeLaunchpadItems = quickpick . activeItems . filter (
581- ( i ) : i is LaunchpadItemQuickPickItem => 'item' in i ,
582- ) ;
583-
584- if ( ! value ?. length || activeLaunchpadItems . length ) {
593+ if ( ! value ?. length ) {
585594 // Nothing to search
586595 this . updateItemsDebouncer . cancel ( ) ;
587596 return true ;
@@ -593,7 +602,9 @@ export class LaunchpadCommand extends QuickCommand<State> {
593602 // Then when we iterate local items we can check them to corresponding identitie according to the item's repo type.
594603 // Same with API: we iterate connected integrations and search in each of them with the corresponding identity.
595604 const prUrlIdentity = getPullRequestIdentityValuesFromSearch ( value ) ;
605+
596606 if ( prUrlIdentity . prNumber != null ) {
607+ // We can identify the PR number, so let's try to find it locally:
597608 const launchpadItems = quickpick . items . filter ( ( i ) : i is LaunchpadItemQuickPickItem => 'item' in i ) ;
598609 let item = launchpadItems . find ( i =>
599610 // perform strict match first
@@ -608,16 +619,15 @@ export class LaunchpadCommand extends QuickCommand<State> {
608619 item . alwaysShow = true ;
609620 // Force quickpick to update by changing the items object:
610621 quickpick . items = [ ...quickpick . items ] ;
611- // We have found an item that matches to the URL.
612- // Now it will be displayed as the found item and we exit this function now without sending any requests to API:
613- this . updateItemsDebouncer . cancel ( ) ;
614- return true ;
615622 }
616- // Nothing is found above, so let's perform search in the API:
617- await updateItems ( quickpick ) ;
623+ // We have found an item that matches to the URL.
624+ // Now it will be displayed as the found item and we exit this function now without sending any requests to API:
625+ this . updateItemsDebouncer . cancel ( ) ;
626+ return true ;
618627 }
619628 }
620- this . updateItemsDebouncer . cancel ( ) ;
629+
630+ await updateItems ( quickpick ) ;
621631 return true ;
622632 } ,
623633 onDidClickButton : async ( quickpick , button ) => {
0 commit comments