Skip to content

Commit

Permalink
Enable restoring a selected kernel that is not yet registered
Browse files Browse the repository at this point in the history
  • Loading branch information
roblourens committed Feb 2, 2023
1 parent 0291e43 commit 60ef912
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1640,13 +1640,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD

private _restoreSelectedKernel(viewState: INotebookEditorViewState | undefined): void {
if (viewState?.selectedKernelId && this.textModel) {
const matching = this.notebookKernelService.getMatchingKernel(this.textModel);
const kernel = matching.all.find(k => k.id === viewState.selectedKernelId);
// Selected kernel may have already been picked prior to the view state loading
// If so, don't overwrite it with the saved kernel.
if (kernel && !matching.selected) {
this.notebookKernelService.selectKernelForNotebook(kernel, this.textModel);
}
this.notebookKernelService.restoreKernelIdForNotebook(viewState.selectedKernelId, this.textModel);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,16 @@ export class NotebookKernelService extends Disposable implements INotebookKernel
}
}

restoreKernelIdForNotebook(kernelId: string, notebook: INotebookTextModelLike): void {
const key = NotebookTextModelLikeId.str(notebook);
const oldKernel = this._notebookBindings.get(key);
if (!oldKernel) {
this._notebookBindings.set(key, kernelId);
this._onDidChangeNotebookKernelBinding.fire({ notebook: notebook.uri, oldKernel, newKernel: kernelId });
this._persistMementos();
}
}

preselectKernelForNotebook(kernel: INotebookKernel, notebook: INotebookTextModelLike): void {
const key = NotebookTextModelLikeId.str(notebook);
const oldKernel = this._notebookBindings.get(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ export interface INotebookKernelService {
*/
selectKernelForNotebook(kernel: INotebookKernel, notebook: INotebookTextModelLike): void;

/**
* Restore a previously selected kernel id. The kernel may or may not be registered yet
* when this is called.
*/
restoreKernelIdForNotebook(kernelId: string, notebook: INotebookTextModelLike): void;

/**
* Set the kernel that a notebook should use when it starts up
*/
Expand Down

0 comments on commit 60ef912

Please sign in to comment.