diff --git a/src/client/datascience/interactive-window/nativeInteractiveWindowProvider.ts b/src/client/datascience/interactive-window/nativeInteractiveWindowProvider.ts index 22911cd2f3b..82d07e5d779 100644 --- a/src/client/datascience/interactive-window/nativeInteractiveWindowProvider.ts +++ b/src/client/datascience/interactive-window/nativeInteractiveWindowProvider.ts @@ -3,7 +3,7 @@ 'use strict'; import { inject, injectable, named } from 'inversify'; import { ConfigurationTarget, Event, EventEmitter, Memento, workspace, window, ViewColumn } from 'vscode'; -import { IPythonApiProvider, IPythonExtensionChecker } from '../../api/types'; +import { IPythonExtensionChecker } from '../../api/types'; import { IApplicationShell, @@ -30,7 +30,6 @@ import { noop } from '../../common/utils/misc'; import { IServiceContainer } from '../../ioc/types'; import { IExportDialog } from '../export/types'; import { IKernelProvider } from '../jupyter/kernels/types'; -import { InteractiveWindowView } from '../notebook/constants'; import { INotebookControllerManager } from '../notebook/types'; import { IInteractiveWindow, @@ -77,8 +76,7 @@ export class NativeInteractiveWindowProvider implements IInteractiveWindowProvid @inject(IWorkspaceService) private readonly workspaceService: IWorkspaceService, @inject(IKernelProvider) private readonly kernelProvider: IKernelProvider, @inject(INotebookControllerManager) private readonly notebookControllerManager: INotebookControllerManager, - @inject(ICommandManager) private readonly commandManager: ICommandManager, - @inject(IPythonApiProvider) private readonly pythonApi: IPythonApiProvider + @inject(ICommandManager) private readonly commandManager: ICommandManager ) { asyncRegistry.push(this); } @@ -238,19 +236,8 @@ export class NativeInteractiveWindowProvider implements IInteractiveWindowProvid } private async getControllerForInteractiveWindow(): Promise { - // Fetch the active interpreter and use the matching controller - const api = await this.pythonApi.getApi(); - const activeInterpreter = await api.getActiveInterpreter(); - - if (!activeInterpreter) { - return; - } - const preferredController = this.notebookControllerManager.getOrCreateController( - activeInterpreter, - InteractiveWindowView - ); - - return preferredController !== undefined ? `${JVSC_EXTENSION_ID}/${preferredController.id}` : undefined; + const preferredController = await this.notebookControllerManager.getInteractiveController(); + return preferredController ? `${JVSC_EXTENSION_ID}/${preferredController.id}` : undefined; } // TODO: we don't currently have a way to know when the VS Code InteractiveEditor diff --git a/src/client/datascience/notebook/notebookControllerManager.ts b/src/client/datascience/notebook/notebookControllerManager.ts index d09713a3cfc..7871fadccad 100644 --- a/src/client/datascience/notebook/notebookControllerManager.ts +++ b/src/client/datascience/notebook/notebookControllerManager.ts @@ -36,7 +36,7 @@ import { sendTelemetryEvent } from '../../telemetry'; import { NotebookCellLanguageService } from './cellLanguageService'; import { sendKernelListTelemetry } from '../telemetry/kernelTelemetry'; import { noop } from '../../common/utils/misc'; -import { IPythonExtensionChecker } from '../../api/types'; +import { IPythonApiProvider, IPythonExtensionChecker } from '../../api/types'; import { PythonEnvironment } from '../../pythonEnvironments/info'; import { isCI } from '../../common/constants'; /** @@ -77,7 +77,8 @@ export class NotebookControllerManager implements INotebookControllerManager, IE @inject(NotebookCellLanguageService) private readonly languageService: NotebookCellLanguageService, @inject(IWorkspaceService) private readonly workspace: IWorkspaceService, @inject(IPythonExtensionChecker) private readonly extensionChecker: IPythonExtensionChecker, - @inject(IDocumentManager) private readonly docManager: IDocumentManager + @inject(IDocumentManager) private readonly docManager: IDocumentManager, + @inject(IPythonApiProvider) private readonly pythonApi: IPythonApiProvider ) { this._onNotebookControllerSelected = new EventEmitter<{ notebook: NotebookDocument; @@ -86,6 +87,16 @@ export class NotebookControllerManager implements INotebookControllerManager, IE this.disposables.push(this._onNotebookControllerSelected); this.isLocalLaunch = isLocalLaunch(this.configuration); } + public async getInteractiveController(): Promise { + // Fetch the active interpreter and use the matching controller + const api = await this.pythonApi.getApi(); + const activeInterpreter = await api.getActiveInterpreter(); + + if (!activeInterpreter) { + return; + } + this.getOrCreateController(activeInterpreter, InteractiveWindowView)?.id; + } get onNotebookControllerSelected() { return this._onNotebookControllerSelected.event; diff --git a/src/client/datascience/notebook/types.ts b/src/client/datascience/notebook/types.ts index 4c593f1ea8d..15cc53faea5 100644 --- a/src/client/datascience/notebook/types.ts +++ b/src/client/datascience/notebook/types.ts @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. import { Event, NotebookDocument, NotebookEditor, Uri } from 'vscode'; -import { PythonEnvironment } from '../../pythonEnvironments/info'; import { VSCodeNotebookController } from './vscodeNotebookController'; export const INotebookKernelResolver = Symbol('INotebookKernelResolver'); @@ -13,10 +12,7 @@ export interface INotebookControllerManager { getSelectedNotebookController(document: NotebookDocument): VSCodeNotebookController | undefined; // Marked test only, just for tests to access registered controllers registeredNotebookControllers(): VSCodeNotebookController[]; - getOrCreateController( - pythonInterpreter: PythonEnvironment, - notebookType: 'interactive' | 'jupyter-notebook' - ): VSCodeNotebookController | undefined; + getInteractiveController(): Promise; } export enum CellOutputMimeTypes { error = 'application/vnd.code.notebook.error',