@@ -23,7 +23,7 @@ import { IExtensionsViewPaneContainer, IExtensionsWorkbenchService, VIEWLET_ID a
2323import { getNotebookEditorFromEditorPane , INotebookEditor , INotebookExtensionRecommendation , JUPYTER_EXTENSION_ID , KERNEL_RECOMMENDATIONS } from 'vs/workbench/contrib/notebook/browser/notebookBrowser' ;
2424import { NotebookEditorWidget } from 'vs/workbench/contrib/notebook/browser/notebookEditorWidget' ;
2525import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel' ;
26- import { INotebookKernel , INotebookKernelMatchResult , INotebookKernelService , ISourceAction } from 'vs/workbench/contrib/notebook/common/notebookKernelService' ;
26+ import { INotebookKernel , INotebookKernelHistoryService , INotebookKernelMatchResult , INotebookKernelService , ISourceAction } from 'vs/workbench/contrib/notebook/common/notebookKernelService' ;
2727import { IEditorService } from 'vs/workbench/services/editor/common/editorService' ;
2828import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions' ;
2929import { IPaneCompositePartService } from 'vs/workbench/services/panecomposite/browser/panecomposite' ;
@@ -129,7 +129,7 @@ abstract class KernelPickerStrategyBase implements IKernelPickerStrategy {
129129
130130 const notebook = editor . textModel ;
131131 const scopedContextKeyService = editor . scopedContextKeyService ;
132- const matchResult = this . _notebookKernelService . getMatchingKernel ( notebook ) ;
132+ const matchResult = this . _getMatchingResult ( notebook ) ;
133133 const { selected, all } = matchResult ;
134134
135135 if ( selected && controllerId && selected . id === controllerId && ExtensionIdentifier . equals ( selected . extension , extensionId ) ) {
@@ -153,7 +153,7 @@ abstract class KernelPickerStrategyBase implements IKernelPickerStrategy {
153153 }
154154
155155 if ( newKernel ) {
156- this . _notebookKernelService . selectKernelForNotebook ( newKernel , notebook ) ;
156+ this . _selecteKernel ( notebook , newKernel ) ;
157157 return true ;
158158 }
159159
@@ -191,7 +191,7 @@ abstract class KernelPickerStrategyBase implements IKernelPickerStrategy {
191191 extensionRecommendataionPromise ?. cancel ( ) ;
192192
193193 const currentActiveItems = quickPick . activeItems ;
194- const matchResult = this . _notebookKernelService . getMatchingKernel ( notebook ) ;
194+ const matchResult = this . _getMatchingResult ( notebook ) ;
195195 const quickPickItems = this . _getKernelPickerQuickPickItems ( notebook , matchResult , this . _notebookKernelService , scopedContextKeyService ) ;
196196 quickPick . keepScrollPosition = true ;
197197
@@ -244,6 +244,10 @@ abstract class KernelPickerStrategyBase implements IKernelPickerStrategy {
244244 return false ;
245245 }
246246
247+ protected _getMatchingResult ( notebook : NotebookTextModel ) {
248+ return this . _notebookKernelService . getMatchingKernel ( notebook ) ;
249+ }
250+
247251 protected abstract _getKernelPickerQuickPickItems (
248252 notebookTextModel : NotebookTextModel ,
249253 matchResult : INotebookKernelMatchResult ,
@@ -254,7 +258,7 @@ abstract class KernelPickerStrategyBase implements IKernelPickerStrategy {
254258 protected async _handleQuickPick ( notebook : NotebookTextModel , pick : KernelQuickPickItem , context ?: KernelQuickPickContext ) {
255259 if ( isKernelPick ( pick ) ) {
256260 const newKernel = pick . kernel ;
257- this . _notebookKernelService . selectKernelForNotebook ( newKernel , notebook ) ;
261+ this . _selecteKernel ( notebook , newKernel ) ;
258262 return true ;
259263 }
260264
@@ -284,6 +288,10 @@ abstract class KernelPickerStrategyBase implements IKernelPickerStrategy {
284288 return true ;
285289 }
286290
291+ protected _selecteKernel ( notebook : NotebookTextModel , kernel : INotebookKernel ) {
292+ this . _notebookKernelService . selectKernelForNotebook ( kernel , notebook ) ;
293+ }
294+
287295 private async _showKernelExtension (
288296 paneCompositePartService : IPaneCompositePartService ,
289297 extensionWorkbenchService : IExtensionsWorkbenchService ,
@@ -574,7 +582,8 @@ export class KernelPickerMRUStrategy extends KernelPickerStrategyBase {
574582 @IPaneCompositePartService _paneCompositePartService : IPaneCompositePartService ,
575583 @IExtensionsWorkbenchService _extensionWorkbenchService : IExtensionsWorkbenchService ,
576584 @IExtensionService _extensionService : IExtensionService ,
577- @ICommandService _commandService : ICommandService
585+ @ICommandService _commandService : ICommandService ,
586+ @INotebookKernelHistoryService private readonly _notebookKernelHistoryService : INotebookKernelHistoryService ,
578587
579588 ) {
580589 super (
@@ -590,6 +599,7 @@ export class KernelPickerMRUStrategy extends KernelPickerStrategyBase {
590599 _commandService ,
591600 ) ;
592601 }
602+
593603 protected _getKernelPickerQuickPickItems ( notebookTextModel : NotebookTextModel , matchResult : INotebookKernelMatchResult , notebookKernelService : INotebookKernelService , scopedContextKeyService : IContextKeyService ) : QuickPickInput < KernelQuickPickItem > [ ] {
594604 const quickPickItems : QuickPickInput < KernelQuickPickItem > [ ] = [ ] ;
595605 let previousKind = '' ;
@@ -627,6 +637,22 @@ export class KernelPickerMRUStrategy extends KernelPickerStrategyBase {
627637 return quickPickItems ;
628638 }
629639
640+ protected override _selecteKernel ( notebook : NotebookTextModel , kernel : INotebookKernel ) : void {
641+ super . _selecteKernel ( notebook , kernel ) ;
642+ this . _notebookKernelHistoryService . addMostRecentKernel ( kernel ) ;
643+ }
644+
645+ protected override _getMatchingResult ( notebook : NotebookTextModel ) : INotebookKernelMatchResult {
646+ const { selected, all } = this . _notebookKernelHistoryService . getKernels ( notebook ) ;
647+ const matchingResult = this . _notebookKernelService . getMatchingKernel ( notebook ) ;
648+ return {
649+ selected : selected ,
650+ all : matchingResult . all ,
651+ suggestions : all ,
652+ hidden : [ ]
653+ } ;
654+ }
655+
630656 protected override async _handleQuickPick ( notebook : NotebookTextModel , pick : KernelQuickPickItem , context ?: KernelQuickPickContext ) : Promise < boolean > {
631657 if ( pick . id === 'selectAnother' ) {
632658 return this . displaySelectAnotherQuickPick ( notebook , context ) ;
@@ -659,25 +685,25 @@ export class KernelPickerMRUStrategy extends KernelPickerStrategyBase {
659685 if ( 'command' in quickPick . selectedItems [ 0 ] ) {
660686 const selectedKernelId = await this . _executeCommand < string > ( notebook , quickPick . selectedItems [ 0 ] . command ) ;
661687 if ( selectedKernelId ) {
662- const { all } = await this . _notebookKernelService . getMatchingKernel ( notebook ) ;
688+ const { all } = await this . _getMatchingResult ( notebook ) ;
663689 const kernel = all . find ( kernel => kernel . id === `ms-toolsai.jupyter/${ selectedKernelId } ` ) ;
664690 if ( kernel ) {
665- await this . _notebookKernelService . selectKernelForNotebook ( kernel , notebook ) ;
691+ await this . _selecteKernel ( notebook , kernel ) ;
666692 resolve ( true ) ;
667693 }
668694 resolve ( true ) ;
669695 } else {
670696 return resolve ( this . displaySelectAnotherQuickPick ( notebook ) ) ;
671697 }
672698 } else if ( 'kernel' in quickPick . selectedItems [ 0 ] ) {
673- await this . _notebookKernelService . selectKernelForNotebook ( quickPick . selectedItems [ 0 ] . kernel , notebook ) ;
699+ await this . _selecteKernel ( notebook , quickPick . selectedItems [ 0 ] . kernel ) ;
674700 resolve ( true ) ;
675701 }
676702 }
677703 } ) ) ;
678704 this . _notebookKernelService . getKernelSourceActions2 ( notebook ) . then ( actions => {
679705 quickPick . busy = false ;
680- const matchResult = this . _notebookKernelService . getMatchingKernel ( notebook ) ;
706+ const matchResult = this . _getMatchingResult ( notebook ) ;
681707 const others = matchResult . all . filter ( item => item . extension . value !== JUPYTER_EXTENSION_ID ) ;
682708 quickPickItems . push ( ...others . map ( kernel => ( {
683709 label : kernel . label ,
0 commit comments