@@ -114,6 +114,8 @@ export class InteractiveSessionWidget extends Disposable implements IInteractive
114
114
115
115
private previousTreeScrollHeight : number = 0 ;
116
116
117
+ private currentViewModelPromise : Promise < IInteractiveSessionViewModel | undefined > | undefined ;
118
+
117
119
private viewModelDisposables = new DisposableStore ( ) ;
118
120
private _viewModel : InteractiveSessionViewModel | undefined ;
119
121
private set viewModel ( viewModel : InteractiveSessionViewModel | undefined ) {
@@ -506,34 +508,39 @@ export class InteractiveSessionWidget extends Disposable implements IInteractive
506
508
}
507
509
508
510
private async initializeSessionModel ( initial = false ) {
509
- if ( this . viewModel ) {
511
+ if ( this . currentViewModelPromise ) {
510
512
return ;
511
513
}
512
514
513
- await this . extensionService . whenInstalledExtensionsRegistered ( ) ;
514
- const model = await this . interactiveSessionService . startSession ( this . providerId , initial , CancellationToken . None ) ;
515
- if ( ! model ) {
516
- throw new Error ( 'Failed to start session' ) ;
517
- }
518
-
519
- if ( this . viewModel ) {
520
- // Oops, created two. TODO this could be better
521
- return ;
522
- }
515
+ const doInitializeSessionModel = async ( ) => {
516
+ await this . extensionService . whenInstalledExtensionsRegistered ( ) ;
517
+ const model = await this . interactiveSessionService . startSession ( this . providerId , initial , CancellationToken . None ) ;
518
+ if ( ! model ) {
519
+ throw new Error ( 'Failed to start session' ) ;
520
+ }
523
521
524
- this . viewModel = this . instantiationService . createInstance ( InteractiveSessionViewModel , model ) ;
525
- this . viewModelDisposables . add ( this . viewModel . onDidChange ( ( ) => {
526
- this . slashCommandsPromise = undefined ;
527
- this . onDidChangeItems ( ) ;
528
- } ) ) ;
529
- this . viewModelDisposables . add ( this . viewModel . onDidDisposeModel ( ( ) => {
530
- this . viewModel = undefined ;
531
- this . onDidChangeItems ( ) ;
532
- } ) ) ;
522
+ if ( this . viewModel ) {
523
+ // Oops, created two. TODO this could be better
524
+ return ;
525
+ }
533
526
534
- if ( this . tree ) {
535
- this . onDidChangeItems ( ) ;
536
- }
527
+ this . viewModel = this . instantiationService . createInstance ( InteractiveSessionViewModel , model ) ;
528
+ this . viewModelDisposables . add ( this . viewModel . onDidChange ( ( ) => {
529
+ this . slashCommandsPromise = undefined ;
530
+ this . onDidChangeItems ( ) ;
531
+ } ) ) ;
532
+ this . viewModelDisposables . add ( this . viewModel . onDidDisposeModel ( ( ) => {
533
+ this . viewModel = undefined ;
534
+ this . onDidChangeItems ( ) ;
535
+ } ) ) ;
536
+
537
+ if ( this . tree ) {
538
+ this . onDidChangeItems ( ) ;
539
+ }
540
+ } ;
541
+ this . currentViewModelPromise = doInitializeSessionModel ( )
542
+ . then ( ( ) => this . viewModel ) ;
543
+ await this . currentViewModelPromise ;
537
544
}
538
545
539
546
async acceptInput ( query ?: string | IInteractiveSessionReplyFollowup ) : Promise < void > {
@@ -571,6 +578,10 @@ export class InteractiveSessionWidget extends Disposable implements IInteractive
571
578
}
572
579
}
573
580
581
+ async waitForViewModel ( ) : Promise < IInteractiveSessionViewModel | undefined > {
582
+ return this . currentViewModelPromise ;
583
+ }
584
+
574
585
focusLastMessage ( ) : void {
575
586
if ( ! this . viewModel ) {
576
587
return ;
0 commit comments