diff --git a/CHANGELOG.md b/CHANGELOG.md index 8dad773a9658..7a28b25430b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -96,6 +96,8 @@ ([#12155](https://github.com/Microsoft/vscode-python/issues/12155)) 1. Make stop during run by line interrupt the kernel. ([#12249](https://github.com/Microsoft/vscode-python/issues/12249)) +1. Have raw kernel respect the jupyter server disable auto start setting. + ([#12246](https://github.com/Microsoft/vscode-python/issues/12246)) ### Code Health diff --git a/src/client/datascience/interactive-common/notebookProvider.ts b/src/client/datascience/interactive-common/notebookProvider.ts index 3ba68a4a1022..83755403f969 100644 --- a/src/client/datascience/interactive-common/notebookProvider.ts +++ b/src/client/datascience/interactive-common/notebookProvider.ts @@ -4,7 +4,7 @@ 'use strict'; import { inject, injectable } from 'inversify'; -import { CancellationToken, EventEmitter, Uri } from 'vscode'; +import { EventEmitter, Uri } from 'vscode'; import { IWorkspaceService } from '../../common/application/types'; import { IFileSystem } from '../../common/platform/types'; import { IDisposableRegistry, Resource } from '../../common/types'; @@ -69,13 +69,10 @@ export class NotebookProvider implements INotebookProvider { } // Attempt to connect to our server provider, and if we do, return the connection info - public async connect( - options: ConnectNotebookProviderOptions, - token?: CancellationToken - ): Promise { + public async connect(options: ConnectNotebookProviderOptions): Promise { // Connect to either a jupyter server or a stubbed out raw notebook "connection" if (await this.rawNotebookProvider.supported()) { - return this.rawNotebookProvider.connect(token); + return this.rawNotebookProvider.connect(options); } else { return this.jupyterNotebookProvider.connect(options); } diff --git a/src/client/datascience/raw-kernel/rawNotebookProvider.ts b/src/client/datascience/raw-kernel/rawNotebookProvider.ts index a4f0b88d3229..8d4e39e34b93 100644 --- a/src/client/datascience/raw-kernel/rawNotebookProvider.ts +++ b/src/client/datascience/raw-kernel/rawNotebookProvider.ts @@ -13,7 +13,13 @@ import * as localize from '../../common/utils/localize'; import { noop } from '../../common/utils/misc'; import { captureTelemetry } from '../../telemetry'; import { Telemetry } from '../constants'; -import { INotebook, IRawConnection, IRawNotebookProvider, IRawNotebookSupportedService } from '../types'; +import { + ConnectNotebookProviderOptions, + INotebook, + IRawConnection, + IRawNotebookProvider, + IRawNotebookSupportedService +} from '../types'; export class RawConnection implements IRawConnection { public readonly type = 'raw'; @@ -36,7 +42,7 @@ export class RawNotebookProviderBase implements IRawNotebookProvider { } // Keep track of the notebooks that we have provided private notebooks = new Map>(); - private rawConnection = new RawConnection(); + private rawConnection: IRawConnection | undefined; private _id = uuid(); constructor( @@ -47,7 +53,17 @@ export class RawNotebookProviderBase implements IRawNotebookProvider { this.asyncRegistry.push(this); } - public connect(): Promise { + public connect(options: ConnectNotebookProviderOptions): Promise { + // For getOnly, we don't want to create a connection, even though we don't have a server + // here we only want to be "connected" when requested to mimic jupyter server function + if (options.getOnly) { + return Promise.resolve(this.rawConnection); + } + + // If not get only, create if needed and return + if (!this.rawConnection) { + this.rawConnection = new RawConnection(); + } return Promise.resolve(this.rawConnection); } @@ -87,6 +103,11 @@ export class RawNotebookProviderBase implements IRawNotebookProvider { } protected getConnection(): IRawConnection { + // At the time of getConnection force a connection if not created already + // should always have happened already, but the check here lets us avoid returning undefined option + if (!this.rawConnection) { + this.rawConnection = new RawConnection(); + } return this.rawConnection; } diff --git a/src/client/datascience/raw-kernel/rawNotebookProviderWrapper.ts b/src/client/datascience/raw-kernel/rawNotebookProviderWrapper.ts index d188bbaee31e..e1837640764b 100644 --- a/src/client/datascience/raw-kernel/rawNotebookProviderWrapper.ts +++ b/src/client/datascience/raw-kernel/rawNotebookProviderWrapper.ts @@ -23,7 +23,14 @@ import { IRoleBasedObject, RoleBasedFactory } from '../jupyter/liveshare/roleBas import { ILiveShareHasRole } from '../jupyter/liveshare/types'; import { IKernelLauncher } from '../kernel-launcher/types'; import { ProgressReporter } from '../progress/progressReporter'; -import { IDataScience, INotebook, IRawConnection, IRawNotebookProvider, IRawNotebookSupportedService } from '../types'; +import { + ConnectNotebookProviderOptions, + IDataScience, + INotebook, + IRawConnection, + IRawNotebookProvider, + IRawNotebookSupportedService +} from '../types'; import { GuestRawNotebookProvider } from './liveshare/guestRawNotebookProvider'; import { HostRawNotebookProvider } from './liveshare/hostRawNotebookProvider'; @@ -104,9 +111,9 @@ export class RawNotebookProviderWrapper implements IRawNotebookProvider, ILiveSh return notebookProvider.supported(); } - public async connect(): Promise { + public async connect(options: ConnectNotebookProviderOptions): Promise { const notebookProvider = await this.serverFactory.get(); - return notebookProvider.connect(); + return notebookProvider.connect(options); } public async createNotebook( diff --git a/src/client/datascience/types.ts b/src/client/datascience/types.ts index 5c50a0db09ed..e989d077ed1f 100644 --- a/src/client/datascience/types.ts +++ b/src/client/datascience/types.ts @@ -152,7 +152,7 @@ export interface IRawNotebookSupportedService { export const IRawNotebookProvider = Symbol('IRawNotebookProvider'); export interface IRawNotebookProvider extends IAsyncDisposable { supported(): Promise; - connect(token?: CancellationToken): Promise; + connect(connect: ConnectNotebookProviderOptions): Promise; createNotebook( identity: Uri, resource: Resource,