Skip to content

Commit

Permalink
separate start and restore.
Browse files Browse the repository at this point in the history
  • Loading branch information
rebornix committed Jul 13, 2022
1 parent 54a0e44 commit b8f5974
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
40 changes: 20 additions & 20 deletions src/interactive-window/interactiveWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,26 +166,7 @@ export class InteractiveWindow implements IInteractiveWindowLoadable {
}
}

public async start(preferredController: IVSCodeNotebookController | undefined) {
if (preferredController) {
this.preferredController = preferredController;
}
if (!this.notebookEditor) {
if (isInteractiveInputTab(this.notebookEditorOrTab)) {
const document = await workspace.openNotebookDocument(this.notebookEditorOrTab.input.uri);
const editor = await window.showNotebookDocument(document, {
viewColumn: this.notebookEditorOrTab.group.viewColumn
});
this._notebookEditor = editor;
await this.startKernel(
this.preferredController?.controller,
this.preferredController?.connection
).ignoreErrors();
} else {
this._notebookEditor = this.notebookEditorOrTab;
}
}

public start() {
window.onDidChangeActiveNotebookEditor((e) => {
if (e === this.notebookEditor) {
this._onDidChangeViewState.fire();
Expand All @@ -211,6 +192,25 @@ export class InteractiveWindow implements IInteractiveWindowLoadable {
}
}

public async restore(preferredController: IVSCodeNotebookController | undefined) {
if (preferredController) {
this.preferredController = preferredController;
}
if (!this.notebookEditor) {
if (isInteractiveInputTab(this.notebookEditorOrTab)) {
const document = await workspace.openNotebookDocument(this.notebookEditorOrTab.input.uri);
const editor = await window.showNotebookDocument(document, {
viewColumn: this.notebookEditorOrTab.group.viewColumn
});
this._notebookEditor = editor;
} else {
this._notebookEditor = this.notebookEditorOrTab;
}
}

this.start();
}

private async startKernel(
controller: NotebookController | undefined = this.currentKernelInfo.controller,
metadata: KernelConnectionMetadata | undefined = this.currentKernelInfo.metadata
Expand Down
7 changes: 3 additions & 4 deletions src/interactive-window/interactiveWindowProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,14 @@ export class InteractiveWindowProvider
if (!result) {
// No match. Create a new item.
result = await this.create(resource, mode, connection);
// We already check preferred kernel before creating the interactive window
// no need to update it anymore.
await result.start(undefined);
// start the kernel
result.start();
} else {
const preferredController = connection
? this.controllerRegistration.get(connection, InteractiveWindowView)
: await this.controllerDefaultService.computeDefaultController(resource, InteractiveWindowView);

await result.start(preferredController);
await result.restore(preferredController);
}

return result;
Expand Down
3 changes: 2 additions & 1 deletion src/interactive-window/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ export interface IInteractiveWindow extends IInteractiveBase {
readonly inputUri?: Uri;
readonly notebookDocument?: NotebookDocument;
closed: Event<void>;
start(preferredController: IVSCodeNotebookController | undefined): Promise<void>;
start(): void;
restore(preferredController: IVSCodeNotebookController | undefined): Promise<void>;
addCode(code: string, file: Uri, line: number): Promise<boolean>;
addErrorMessage(message: string, cell: NotebookCell): Promise<void>;
debugCode(code: string, file: Uri, line: number): Promise<boolean>;
Expand Down

0 comments on commit b8f5974

Please sign in to comment.