@@ -152,14 +152,21 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
152
152
return ;
153
153
}
154
154
155
+ if ( this . _activeKernel === kernel ) {
156
+ return ;
157
+ }
158
+
155
159
this . _activeKernel = kernel ;
160
+ this . _activeKernelResolvePromise = undefined ;
156
161
157
162
const memento = this . _activeKernelMemento . getMemento ( StorageScope . GLOBAL ) ;
158
163
memento [ this . viewModel ! . viewType ] = this . _activeKernel ?. id ;
159
164
this . _activeKernelMemento . saveMemento ( ) ;
160
165
this . _onDidChangeKernel . fire ( ) ;
161
166
}
162
167
168
+ private _activeKernelResolvePromise : Promise < void > | undefined = undefined ;
169
+
163
170
private _currentKernelTokenSource : CancellationTokenSource | undefined = undefined ;
164
171
private _multipleKernelsAvailable : boolean = false ;
165
172
@@ -637,7 +644,17 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
637
644
638
645
if ( this . activeKernel ) {
639
646
await this . _loadKernelPreloads ( this . activeKernel . extensionLocation , this . activeKernel ) ;
640
- await this . activeKernel . resolve ( this . viewModel ! . uri , this . getId ( ) , tokenSource . token ) ;
647
+
648
+ if ( tokenSource . token . isCancellationRequested ) {
649
+ return ;
650
+ }
651
+
652
+ this . _activeKernelResolvePromise = this . activeKernel . resolve ( this . viewModel ! . uri , this . getId ( ) , tokenSource . token ) ;
653
+ await this . _activeKernelResolvePromise ;
654
+
655
+ if ( tokenSource . token . isCancellationRequested ) {
656
+ return ;
657
+ }
641
658
}
642
659
643
660
memento [ provider . id ] = this . _activeKernel ?. id ;
@@ -657,8 +674,17 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
657
674
|| kernelsFromSameExtension [ 0 ] ;
658
675
this . activeKernel = preferedKernel ;
659
676
await this . _loadKernelPreloads ( this . activeKernel . extensionLocation , this . activeKernel ) ;
677
+
678
+ if ( tokenSource . token . isCancellationRequested ) {
679
+ return ;
680
+ }
681
+
660
682
await preferedKernel . resolve ( this . viewModel ! . uri , this . getId ( ) , tokenSource . token ) ;
661
683
684
+ if ( tokenSource . token . isCancellationRequested ) {
685
+ return ;
686
+ }
687
+
662
688
memento [ provider . id ] = this . _activeKernel ?. id ;
663
689
this . _activeKernelMemento . saveMemento ( ) ;
664
690
tokenSource . dispose ( ) ;
@@ -669,7 +695,14 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
669
695
this . activeKernel = kernels [ 0 ] ;
670
696
if ( this . activeKernel ) {
671
697
await this . _loadKernelPreloads ( this . activeKernel . extensionLocation , this . activeKernel ) ;
698
+ if ( tokenSource . token . isCancellationRequested ) {
699
+ return ;
700
+ }
701
+
672
702
await this . activeKernel . resolve ( this . viewModel ! . uri , this . getId ( ) , tokenSource . token ) ;
703
+ if ( tokenSource . token . isCancellationRequested ) {
704
+ return ;
705
+ }
673
706
}
674
707
675
708
tokenSource . dispose ( ) ;
@@ -1296,6 +1329,10 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
1296
1329
if ( this . _activeKernel ) {
1297
1330
// TODO@rebornix temp any cast, should be removed once we remove legacy kernel support
1298
1331
if ( ( this . _activeKernel as INotebookKernelInfo2 ) . executeNotebookCell ) {
1332
+ if ( this . _activeKernelResolvePromise ) {
1333
+ await this . _activeKernelResolvePromise ;
1334
+ }
1335
+
1299
1336
await ( this . _activeKernel as INotebookKernelInfo2 ) . executeNotebookCell ! ( this . _notebookViewModel ! . uri , undefined ) ;
1300
1337
} else {
1301
1338
await this . notebookService . executeNotebook2 ( this . _notebookViewModel ! . viewType , this . _notebookViewModel ! . uri , this . _activeKernel . id ) ;
0 commit comments