Skip to content

Connection type refactor #11272

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { Common, DataScience } from '../../common/utils/localize';
import { IInterpreterService } from '../../interpreter/contracts';
import { sendTelemetryEvent } from '../../telemetry';
import { Telemetry } from '../constants';
import { IConnection, ILocalResourceUriConverter, INotebook } from '../types';
import { ILocalResourceUriConverter, INotebook } from '../types';
import { CDNWidgetScriptSourceProvider } from './cdnWidgetScriptSourceProvider';
import { LocalWidgetScriptSourceProvider } from './localWidgetScriptSourceProvider';
import { RemoteWidgetScriptSourceProvider } from './remoteWidgetScriptSourceProvider';
Expand Down Expand Up @@ -135,9 +135,7 @@ export class IPyWidgetScriptSourceProvider implements IWidgetScriptSourceProvide
);
} else {
if (this.notebook.connection) {
scriptProviders.push(
new RemoteWidgetScriptSourceProvider(this.notebook.connection as IConnection, this.httpClient)
);
scriptProviders.push(new RemoteWidgetScriptSourceProvider(this.notebook.connection, this.httpClient));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { traceWarning } from '../../common/logger';
import { IHttpClient } from '../../common/types';
import { IConnection } from '../types';
import { IJupyterConnection } from '../types';
import { IWidgetScriptSourceProvider, WidgetScriptSource } from './types';

/**
Expand All @@ -14,7 +14,7 @@ import { IWidgetScriptSourceProvider, WidgetScriptSource } from './types';
*/
export class RemoteWidgetScriptSourceProvider implements IWidgetScriptSourceProvider {
public static validUrls = new Map<string, boolean>();
constructor(private readonly connection: IConnection, private readonly httpClient: IHttpClient) {}
constructor(private readonly connection: IJupyterConnection, private readonly httpClient: IHttpClient) {}
public dispose() {
// Noop.
}
Expand Down
10 changes: 5 additions & 5 deletions src/client/datascience/jupyter/jupyterConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { createDeferred, Deferred } from '../../common/utils/async';
import * as localize from '../../common/utils/localize';
import { IServiceContainer } from '../../ioc/types';
import { RegExpValues } from '../constants';
import { IConnection } from '../types';
import { IJupyterConnection } from '../types';
import { JupyterConnectError } from './jupyterConnectError';

// tslint:disable-next-line:no-require-imports no-var-requires no-any
Expand All @@ -34,7 +34,7 @@ export type JupyterServerInfo = {
};

export class JupyterConnectionWaiter implements IDisposable {
private startPromise: Deferred<IConnection>;
private startPromise: Deferred<IJupyterConnection>;
private launchTimeout: NodeJS.Timer | number;
private configService: IConfigurationService;
private fileSystem: IFileSystem;
Expand All @@ -57,7 +57,7 @@ export class JupyterConnectionWaiter implements IDisposable {
}

// Setup our start promise
this.startPromise = createDeferred<IConnection>();
this.startPromise = createDeferred<IJupyterConnection>();

// We want to reject our Jupyter connection after a specific timeout
const settings = this.configService.getSettings(undefined);
Expand Down Expand Up @@ -94,7 +94,7 @@ export class JupyterConnectionWaiter implements IDisposable {
clearTimeout(this.launchTimeout as any);
}

public waitForConnection(): Promise<IConnection> {
public waitForConnection(): Promise<IJupyterConnection> {
return this.startPromise.promise;
}

Expand Down Expand Up @@ -215,7 +215,7 @@ export class JupyterConnectionWaiter implements IDisposable {
}

// Represents an active connection to a running jupyter notebook
class JupyterConnection implements IConnection {
class JupyterConnection implements IJupyterConnection {
public readonly localLaunch: boolean = true;
public readonly type = 'jupyter';
public valid: boolean = true;
Expand Down
8 changes: 3 additions & 5 deletions src/client/datascience/jupyter/jupyterDebugger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import {
CellState,
ICell,
ICellHashListener,
IConnection,
IFileHashes,
IJupyterConnection,
IJupyterDebugger,
INotebook,
ISourceMapRequest
Expand Down Expand Up @@ -176,9 +176,7 @@ export class JupyterDebugger implements IJupyterDebugger, ICellHashListener {
// Connect local or remote based on what type of notebook we're talking to
const connectionInfo = notebook.connection;
if (connectionInfo && !connectionInfo.localLaunch) {
// Remote connections are always jupyter
const jupyterConnection = connectionInfo as IConnection;
result = await this.connectToRemote(notebook, jupyterConnection);
result = await this.connectToRemote(notebook, connectionInfo);
} else {
result = await this.connectToLocal(notebook);
}
Expand Down Expand Up @@ -481,7 +479,7 @@ export class JupyterDebugger implements IJupyterDebugger, ICellHashListener {

private async connectToRemote(
_notebook: INotebook,
_connectionInfo: IConnection
_connectionInfo: IJupyterConnection
): Promise<DebugConfiguration | undefined> {
// We actually need a token. This isn't supported at the moment
throw new JupyterDebuggerRemoteNotSupported();
Expand Down
8 changes: 4 additions & 4 deletions src/client/datascience/jupyter/jupyterExecution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { captureTelemetry, sendTelemetryEvent } from '../../telemetry';
import { JupyterSessionStartError } from '../baseJupyterSession';
import { Commands, Telemetry } from '../constants';
import {
IConnection,
IJupyterConnection,
IJupyterExecution,
IJupyterSessionManagerFactory,
IJupyterSubCommandExecutionService,
Expand Down Expand Up @@ -126,7 +126,7 @@ export class JupyterExecutionBase implements IJupyterExecution {
// tslint:disable-next-line: max-func-body-length
return Cancellation.race(async () => {
let result: INotebookServer | undefined;
let connection: IConnection | undefined;
let connection: IJupyterConnection | undefined;
let kernelSpecInterpreter: KernelSpecInterpreter | undefined;
let kernelSpecInterpreterPromise: Promise<KernelSpecInterpreter> = Promise.resolve({});
traceInfo(`Connecting to ${options ? options.purpose : 'unknown type of'} server`);
Expand Down Expand Up @@ -335,7 +335,7 @@ export class JupyterExecutionBase implements IJupyterExecution {
private async startOrConnect(
options?: INotebookServerOptions,
cancelToken?: CancellationToken
): Promise<IConnection> {
): Promise<IJupyterConnection> {
// If our uri is undefined or if it's set to local launch we need to launch a server locally
if (!options || !options.uri) {
// If that works, then attempt to start the server
Expand Down Expand Up @@ -367,7 +367,7 @@ export class JupyterExecutionBase implements IJupyterExecution {
useDefaultConfig: boolean,
customCommandLine: string[],
cancelToken?: CancellationToken
): Promise<IConnection> {
): Promise<IJupyterConnection> {
return this.notebookStarter.start(useDefaultConfig, customCommandLine, cancelToken);
}
private onSettingsChanged() {
Expand Down
6 changes: 2 additions & 4 deletions src/client/datascience/jupyter/jupyterNotebook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import { CodeSnippits, Identifiers, Telemetry } from '../constants';
import {
CellState,
ICell,
IConnection,
IJupyterKernelSpec,
IJupyterSession,
INotebook,
Expand Down Expand Up @@ -996,10 +995,9 @@ export class JupyterNotebookBase implements INotebook {
private checkForExit(): Error | undefined {
if (this._executionInfo && this._executionInfo.connectionInfo && !this._executionInfo.connectionInfo.valid) {
if (this._executionInfo.connectionInfo.type === 'jupyter') {
const jupyterConnection = this._executionInfo.connectionInfo as IConnection;
// Not running, just exit
if (jupyterConnection.localProcExitCode) {
const exitCode = jupyterConnection.localProcExitCode;
if (this._executionInfo.connectionInfo.localProcExitCode) {
const exitCode = this._executionInfo.connectionInfo.localProcExitCode;
traceError(`Jupyter crashed with code ${exitCode}`);
return new Error(localize.DataScience.jupyterServerCrashed().format(exitCode.toString()));
}
Expand Down
4 changes: 2 additions & 2 deletions src/client/datascience/jupyter/jupyterNotebookProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as localize from '../../common/utils/localize';
import {
ConnectNotebookProviderOptions,
GetNotebookOptions,
IConnection,
IJupyterConnection,
IJupyterNotebookProvider,
IJupyterServerProvider,
INotebook
Expand All @@ -25,7 +25,7 @@ export class JupyterNotebookProvider implements IJupyterNotebookProvider {
return server?.dispose();
}

public async connect(options: ConnectNotebookProviderOptions): Promise<IConnection | undefined> {
public async connect(options: ConnectNotebookProviderOptions): Promise<IJupyterConnection | undefined> {
const server = await this.serverProvider.getOrCreateServer(options);
return server?.getConnectionInfo();
}
Expand Down
4 changes: 2 additions & 2 deletions src/client/datascience/jupyter/jupyterServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import * as localize from '../../common/utils/localize';
import { noop } from '../../common/utils/misc';
import { IServiceContainer } from '../../ioc/types';
import {
IConnection,
IJupyterConnection,
IJupyterSession,
IJupyterSessionManager,
IJupyterSessionManagerFactory,
Expand Down Expand Up @@ -176,7 +176,7 @@ export class JupyterServerBase implements INotebookServer {
}

// Return a copy of the connection information that this server used to connect with
public getConnectionInfo(): IConnection | undefined {
public getConnectionInfo(): IJupyterConnection | undefined {
if (!this.launchInfo) {
return undefined;
}
Expand Down
4 changes: 2 additions & 2 deletions src/client/datascience/jupyter/jupyterServerWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import { IInterpreterService } from '../../interpreter/contracts';
import { IServiceContainer } from '../../ioc/types';
import { JUPYTER_OUTPUT_CHANNEL } from '../constants';
import {
IConnection,
IDataScience,
IJupyterConnection,
IJupyterSessionManagerFactory,
INotebook,
INotebookServer,
Expand Down Expand Up @@ -137,7 +137,7 @@ export class JupyterServerWrapper implements INotebookServer, ILiveShareHasRole
}

// Return a copy of the connection information that this server used to connect with
public getConnectionInfo(): IConnection | undefined {
public getConnectionInfo(): IJupyterConnection | undefined {
if (this.launchInfo) {
return this.launchInfo.connectionInfo;
}
Expand Down
4 changes: 2 additions & 2 deletions src/client/datascience/jupyter/jupyterSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { BaseJupyterSession, ISession, JupyterSessionStartError } from '../baseJ
import { Telemetry } from '../constants';
import { reportAction } from '../progress/decorator';
import { ReportableAction } from '../progress/types';
import { IConnection, IJupyterKernelSpec } from '../types';
import { IJupyterConnection, IJupyterKernelSpec } from '../types';
import { JupyterInvalidKernelError } from './jupyterInvalidKernelError';
import { JupyterWaitForIdleError } from './jupyterWaitForIdleError';
import { KernelSelector } from './kernels/kernelSelector';
Expand All @@ -35,7 +35,7 @@ import { LiveKernelModel } from './kernels/types';
export class JupyterSession extends BaseJupyterSession {
private notebookFiles: Contents.IModel[] = [];
constructor(
private connInfo: IConnection,
private connInfo: IJupyterConnection,
private serverSettings: ServerConnection.ISettings,
kernelSpec: IJupyterKernelSpec | LiveKernelModel | undefined,
private sessionManager: SessionManager,
Expand Down
10 changes: 5 additions & 5 deletions src/client/datascience/jupyter/jupyterSessionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { IConfigurationService, IOutputChannel } from '../../common/types';
import * as localize from '../../common/utils/localize';
import { noop } from '../../common/utils/misc';
import {
IConnection,
IJupyterConnection,
IJupyterKernel,
IJupyterKernelSpec,
IJupyterPasswordConnect,
Expand All @@ -27,7 +27,7 @@ import { LiveKernelModel } from './kernels/types';
export class JupyterSessionManager implements IJupyterSessionManager {
private sessionManager: SessionManager | undefined;
private contentsManager: ContentsManager | undefined;
private connInfo: IConnection | undefined;
private connInfo: IJupyterConnection | undefined;
private serverSettings: ServerConnection.ISettings | undefined;

constructor(
Expand Down Expand Up @@ -71,11 +71,11 @@ export class JupyterSessionManager implements IJupyterSessionManager {
}
}

public getConnInfo(): IConnection {
public getConnInfo(): IJupyterConnection {
return this.connInfo!;
}

public async initialize(connInfo: IConnection): Promise<void> {
public async initialize(connInfo: IJupyterConnection): Promise<void> {
this.connInfo = connInfo;
this.serverSettings = await this.getServerConnectSettings(connInfo);
this.sessionManager = new SessionManager({ serverSettings: this.serverSettings });
Expand Down Expand Up @@ -187,7 +187,7 @@ export class JupyterSessionManager implements IJupyterSessionManager {
return `_xsrf=${pwSettings.xsrfCookie}; ${pwSettings.sessionCookieName}=${pwSettings.sessionCookieValue}`;
}

private async getServerConnectSettings(connInfo: IConnection): Promise<ServerConnection.ISettings> {
private async getServerConnectSettings(connInfo: IJupyterConnection): Promise<ServerConnection.ISettings> {
let serverSettings: Partial<ServerConnection.ISettings> = {
baseUrl: connInfo.baseUrl,
appUrl: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import { inject, injectable, named } from 'inversify';

import { IConfigurationService, IOutputChannel } from '../../common/types';
import { JUPYTER_OUTPUT_CHANNEL } from '../constants';
import { IConnection, IJupyterPasswordConnect, IJupyterSessionManager, IJupyterSessionManagerFactory } from '../types';
import {
IJupyterConnection,
IJupyterPasswordConnect,
IJupyterSessionManager,
IJupyterSessionManagerFactory
} from '../types';
import { JupyterSessionManager } from './jupyterSessionManager';
import { KernelSelector } from './kernels/kernelSelector';

Expand All @@ -23,7 +28,7 @@ export class JupyterSessionManagerFactory implements IJupyterSessionManagerFacto
* @param connInfo - connection information to the server that's already running.
* @param failOnPassword - whether or not to fail the creation if a password is required.
*/
public async create(connInfo: IConnection, failOnPassword?: boolean): Promise<IJupyterSessionManager> {
public async create(connInfo: IJupyterConnection, failOnPassword?: boolean): Promise<IJupyterSessionManager> {
const result = new JupyterSessionManager(
this.jupyterPasswordConnect,
this.config,
Expand Down
4 changes: 2 additions & 2 deletions src/client/datascience/jupyter/jupyterUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { noop } from '../../common/utils/misc';
import { SystemVariables } from '../../common/variables/systemVariables';
import { Identifiers } from '../constants';
import { getJupyterConnectionDisplayName } from '../jupyter/jupyterConnection';
import { IConnection } from '../types';
import { IJupyterConnection } from '../types';

// tslint:disable-next-line:no-require-imports no-var-requires
const _escapeRegExp = require('lodash/escapeRegExp') as typeof import('lodash/escapeRegExp');
Expand All @@ -31,7 +31,7 @@ export function expandWorkingDir(
return path.dirname(launchingFile);
}

export function createRemoteConnectionInfo(uri: string, settings: IDataScienceSettings): IConnection {
export function createRemoteConnectionInfo(uri: string, settings: IDataScienceSettings): IJupyterConnection {
let url: URL;
try {
url = new URL(uri);
Expand Down
10 changes: 4 additions & 6 deletions src/client/datascience/jupyter/kernels/kernelSwitcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Common, DataScience } from '../../../common/utils/localize';
import { StopWatch } from '../../../common/utils/stopWatch';
import { JupyterSessionStartError } from '../../baseJupyterSession';
import { Commands, Settings } from '../../constants';
import { IConnection, IJupyterKernelSpec, IJupyterSessionManagerFactory, INotebook } from '../../types';
import { IJupyterConnection, IJupyterKernelSpec, IJupyterSessionManagerFactory, INotebook } from '../../types';
import { JupyterInvalidKernelError } from '../jupyterInvalidKernelError';
import { KernelSelector, KernelSpecInterpreter } from './kernelSelector';
import { LiveKernelModel } from './types';
Expand Down Expand Up @@ -60,10 +60,8 @@ export class KernelSwitcher {
} else if (notebook) {
const connInfo = notebook.connection;
const currentKernel = notebook.getKernelSpec();
if (connInfo) {
// Remote connection is always jupyter connection
const jupyterConnInfo = connInfo as IConnection;
kernel = await this.selectRemoteJupyterKernel(notebook.resource, jupyterConnInfo, currentKernel);
if (connInfo && connInfo.type === 'jupyter') {
kernel = await this.selectRemoteJupyterKernel(notebook.resource, connInfo, currentKernel);
}
}
return kernel;
Expand All @@ -78,7 +76,7 @@ export class KernelSwitcher {

private async selectRemoteJupyterKernel(
resource: Resource,
connInfo: IConnection,
connInfo: IJupyterConnection,
currentKernel?: IJupyterKernelSpec | LiveKernelModel
): Promise<KernelSpecInterpreter> {
const stopWatch = new StopWatch();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import * as localize from '../../../common/utils/localize';
import { IInterpreterService, PythonInterpreter } from '../../../interpreter/contracts';
import { IServiceContainer } from '../../../ioc/types';
import { LiveShare, LiveShareCommands } from '../../constants';
import { IConnection, INotebookServer, INotebookServerOptions } from '../../types';
import { IJupyterConnection, INotebookServer, INotebookServerOptions } from '../../types';
import { JupyterConnectError } from '../jupyterConnectError';
import { JupyterExecutionBase } from '../jupyterExecution';
import { KernelSelector } from '../kernels/kernelSelector';
Expand Down Expand Up @@ -87,7 +87,7 @@ export class GuestJupyterExecution extends LiveShareParticipantGuest(
const service = await this.waitForService();
if (service) {
const purpose = options ? options.purpose : uuid();
const connection: IConnection = await service.request(
const connection: IJupyterConnection = await service.request(
LiveShareCommands.connectToNotebookServer,
[options],
cancelToken
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import * as localize from '../../../common/utils/localize';
import { IServiceContainer } from '../../../ioc/types';
import { LiveShare, LiveShareCommands } from '../../constants';
import {
IConnection,
IDataScience,
IJupyterConnection,
IJupyterSessionManagerFactory,
INotebook,
INotebookServer,
Expand Down Expand Up @@ -118,7 +118,7 @@ export class GuestJupyterServer
}

// Return a copy of the connection information that this server used to connect with
public getConnectionInfo(): IConnection | undefined {
public getConnectionInfo(): IJupyterConnection | undefined {
if (this.launchInfo) {
return this.launchInfo.connectionInfo;
}
Expand Down
Loading