Skip to content

Commit 59b1a81

Browse files
Connection type refactor (#11272)
1 parent ce4f48c commit 59b1a81

29 files changed

+114
-102
lines changed

src/client/datascience/ipywidgets/ipyWidgetScriptSourceProvider.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { noop } from '../../common/utils/misc';
2222
import { IInterpreterService } from '../../interpreter/contracts';
2323
import { sendTelemetryEvent } from '../../telemetry';
2424
import { Telemetry } from '../constants';
25-
import { IConnection, ILocalResourceUriConverter, INotebook } from '../types';
25+
import { ILocalResourceUriConverter, INotebook } from '../types';
2626
import { CDNWidgetScriptSourceProvider } from './cdnWidgetScriptSourceProvider';
2727
import { LocalWidgetScriptSourceProvider } from './localWidgetScriptSourceProvider';
2828
import { RemoteWidgetScriptSourceProvider } from './remoteWidgetScriptSourceProvider';
@@ -174,9 +174,7 @@ export class IPyWidgetScriptSourceProvider implements IWidgetScriptSourceProvide
174174
);
175175
} else {
176176
if (this.notebook.connection) {
177-
scriptProviders.push(
178-
new RemoteWidgetScriptSourceProvider(this.notebook.connection as IConnection, this.httpClient)
179-
);
177+
scriptProviders.push(new RemoteWidgetScriptSourceProvider(this.notebook.connection, this.httpClient));
180178
}
181179
}
182180

src/client/datascience/ipywidgets/remoteWidgetScriptSourceProvider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import { traceWarning } from '../../common/logger';
77
import { IHttpClient } from '../../common/types';
8-
import { IConnection } from '../types';
8+
import { IJupyterConnection } from '../types';
99
import { IWidgetScriptSourceProvider, WidgetScriptSource } from './types';
1010

1111
/**
@@ -14,7 +14,7 @@ import { IWidgetScriptSourceProvider, WidgetScriptSource } from './types';
1414
*/
1515
export class RemoteWidgetScriptSourceProvider implements IWidgetScriptSourceProvider {
1616
public static validUrls = new Map<string, boolean>();
17-
constructor(private readonly connection: IConnection, private readonly httpClient: IHttpClient) {}
17+
constructor(private readonly connection: IJupyterConnection, private readonly httpClient: IHttpClient) {}
1818
public dispose() {
1919
// Noop.
2020
}

src/client/datascience/jupyter/jupyterConnection.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { createDeferred, Deferred } from '../../common/utils/async';
1414
import * as localize from '../../common/utils/localize';
1515
import { IServiceContainer } from '../../ioc/types';
1616
import { RegExpValues } from '../constants';
17-
import { IConnection } from '../types';
17+
import { IJupyterConnection } from '../types';
1818
import { JupyterConnectError } from './jupyterConnectError';
1919

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

3636
export class JupyterConnectionWaiter implements IDisposable {
37-
private startPromise: Deferred<IConnection>;
37+
private startPromise: Deferred<IJupyterConnection>;
3838
private launchTimeout: NodeJS.Timer | number;
3939
private configService: IConfigurationService;
4040
private fileSystem: IFileSystem;
@@ -57,7 +57,7 @@ export class JupyterConnectionWaiter implements IDisposable {
5757
}
5858

5959
// Setup our start promise
60-
this.startPromise = createDeferred<IConnection>();
60+
this.startPromise = createDeferred<IJupyterConnection>();
6161

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

97-
public waitForConnection(): Promise<IConnection> {
97+
public waitForConnection(): Promise<IJupyterConnection> {
9898
return this.startPromise.promise;
9999
}
100100

@@ -215,7 +215,7 @@ export class JupyterConnectionWaiter implements IDisposable {
215215
}
216216

217217
// Represents an active connection to a running jupyter notebook
218-
class JupyterConnection implements IConnection {
218+
class JupyterConnection implements IJupyterConnection {
219219
public readonly localLaunch: boolean = true;
220220
public readonly type = 'jupyter';
221221
public valid: boolean = true;

src/client/datascience/jupyter/jupyterDebugger.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import {
2222
CellState,
2323
ICell,
2424
ICellHashListener,
25-
IConnection,
2625
IFileHashes,
26+
IJupyterConnection,
2727
IJupyterDebugger,
2828
INotebook,
2929
ISourceMapRequest
@@ -176,9 +176,7 @@ export class JupyterDebugger implements IJupyterDebugger, ICellHashListener {
176176
// Connect local or remote based on what type of notebook we're talking to
177177
const connectionInfo = notebook.connection;
178178
if (connectionInfo && !connectionInfo.localLaunch) {
179-
// Remote connections are always jupyter
180-
const jupyterConnection = connectionInfo as IConnection;
181-
result = await this.connectToRemote(notebook, jupyterConnection);
179+
result = await this.connectToRemote(notebook, connectionInfo);
182180
} else {
183181
result = await this.connectToLocal(notebook);
184182
}
@@ -481,7 +479,7 @@ export class JupyterDebugger implements IJupyterDebugger, ICellHashListener {
481479

482480
private async connectToRemote(
483481
_notebook: INotebook,
484-
_connectionInfo: IConnection
482+
_connectionInfo: IJupyterConnection
485483
): Promise<DebugConfiguration | undefined> {
486484
// We actually need a token. This isn't supported at the moment
487485
throw new JupyterDebuggerRemoteNotSupported();

src/client/datascience/jupyter/jupyterExecution.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { captureTelemetry, sendTelemetryEvent } from '../../telemetry';
1818
import { JupyterSessionStartError } from '../baseJupyterSession';
1919
import { Commands, Telemetry } from '../constants';
2020
import {
21-
IConnection,
21+
IJupyterConnection,
2222
IJupyterExecution,
2323
IJupyterSessionManagerFactory,
2424
IJupyterSubCommandExecutionService,
@@ -126,7 +126,7 @@ export class JupyterExecutionBase implements IJupyterExecution {
126126
// tslint:disable-next-line: max-func-body-length
127127
return Cancellation.race(async () => {
128128
let result: INotebookServer | undefined;
129-
let connection: IConnection | undefined;
129+
let connection: IJupyterConnection | undefined;
130130
let kernelSpecInterpreter: KernelSpecInterpreter | undefined;
131131
let kernelSpecInterpreterPromise: Promise<KernelSpecInterpreter> = Promise.resolve({});
132132
traceInfo(`Connecting to ${options ? options.purpose : 'unknown type of'} server`);
@@ -335,7 +335,7 @@ export class JupyterExecutionBase implements IJupyterExecution {
335335
private async startOrConnect(
336336
options?: INotebookServerOptions,
337337
cancelToken?: CancellationToken
338-
): Promise<IConnection> {
338+
): Promise<IJupyterConnection> {
339339
// If our uri is undefined or if it's set to local launch we need to launch a server locally
340340
if (!options || !options.uri) {
341341
// If that works, then attempt to start the server
@@ -367,7 +367,7 @@ export class JupyterExecutionBase implements IJupyterExecution {
367367
useDefaultConfig: boolean,
368368
customCommandLine: string[],
369369
cancelToken?: CancellationToken
370-
): Promise<IConnection> {
370+
): Promise<IJupyterConnection> {
371371
return this.notebookStarter.start(useDefaultConfig, customCommandLine, cancelToken);
372372
}
373373
private onSettingsChanged() {

src/client/datascience/jupyter/jupyterNotebook.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import { CodeSnippits, Identifiers, Telemetry } from '../constants';
2727
import {
2828
CellState,
2929
ICell,
30-
IConnection,
3130
IJupyterKernelSpec,
3231
IJupyterSession,
3332
INotebook,
@@ -999,10 +998,9 @@ export class JupyterNotebookBase implements INotebook {
999998
private checkForExit(): Error | undefined {
1000999
if (this._executionInfo && this._executionInfo.connectionInfo && !this._executionInfo.connectionInfo.valid) {
10011000
if (this._executionInfo.connectionInfo.type === 'jupyter') {
1002-
const jupyterConnection = this._executionInfo.connectionInfo as IConnection;
10031001
// Not running, just exit
1004-
if (jupyterConnection.localProcExitCode) {
1005-
const exitCode = jupyterConnection.localProcExitCode;
1002+
if (this._executionInfo.connectionInfo.localProcExitCode) {
1003+
const exitCode = this._executionInfo.connectionInfo.localProcExitCode;
10061004
traceError(`Jupyter crashed with code ${exitCode}`);
10071005
return new Error(localize.DataScience.jupyterServerCrashed().format(exitCode.toString()));
10081006
}

src/client/datascience/jupyter/jupyterNotebookProvider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import * as localize from '../../common/utils/localize';
88
import {
99
ConnectNotebookProviderOptions,
1010
GetNotebookOptions,
11-
IConnection,
11+
IJupyterConnection,
1212
IJupyterNotebookProvider,
1313
IJupyterServerProvider,
1414
INotebook
@@ -25,7 +25,7 @@ export class JupyterNotebookProvider implements IJupyterNotebookProvider {
2525
return server?.dispose();
2626
}
2727

28-
public async connect(options: ConnectNotebookProviderOptions): Promise<IConnection | undefined> {
28+
public async connect(options: ConnectNotebookProviderOptions): Promise<IJupyterConnection | undefined> {
2929
const server = await this.serverProvider.getOrCreateServer(options);
3030
return server?.getConnectionInfo();
3131
}

src/client/datascience/jupyter/jupyterServer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import * as localize from '../../common/utils/localize';
2020
import { noop } from '../../common/utils/misc';
2121
import { IServiceContainer } from '../../ioc/types';
2222
import {
23-
IConnection,
23+
IJupyterConnection,
2424
IJupyterSession,
2525
IJupyterSessionManager,
2626
IJupyterSessionManagerFactory,
@@ -176,7 +176,7 @@ export class JupyterServerBase implements INotebookServer {
176176
}
177177

178178
// Return a copy of the connection information that this server used to connect with
179-
public getConnectionInfo(): IConnection | undefined {
179+
public getConnectionInfo(): IJupyterConnection | undefined {
180180
if (!this.launchInfo) {
181181
return undefined;
182182
}

src/client/datascience/jupyter/jupyterServerWrapper.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import { IInterpreterService } from '../../interpreter/contracts';
2121
import { IServiceContainer } from '../../ioc/types';
2222
import { JUPYTER_OUTPUT_CHANNEL } from '../constants';
2323
import {
24-
IConnection,
2524
IDataScience,
25+
IJupyterConnection,
2626
IJupyterSessionManagerFactory,
2727
INotebook,
2828
INotebookServer,
@@ -137,7 +137,7 @@ export class JupyterServerWrapper implements INotebookServer, ILiveShareHasRole
137137
}
138138

139139
// Return a copy of the connection information that this server used to connect with
140-
public getConnectionInfo(): IConnection | undefined {
140+
public getConnectionInfo(): IJupyterConnection | undefined {
141141
if (this.launchInfo) {
142142
return this.launchInfo.connectionInfo;
143143
}

src/client/datascience/jupyter/jupyterSession.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { BaseJupyterSession, ISession, JupyterSessionStartError } from '../baseJ
2626
import { Telemetry } from '../constants';
2727
import { reportAction } from '../progress/decorator';
2828
import { ReportableAction } from '../progress/types';
29-
import { IConnection, IJupyterKernelSpec } from '../types';
29+
import { IJupyterConnection, IJupyterKernelSpec } from '../types';
3030
import { JupyterInvalidKernelError } from './jupyterInvalidKernelError';
3131
import { JupyterWaitForIdleError } from './jupyterWaitForIdleError';
3232
import { KernelSelector } from './kernels/kernelSelector';
@@ -35,7 +35,7 @@ import { LiveKernelModel } from './kernels/types';
3535
export class JupyterSession extends BaseJupyterSession {
3636
private notebookFiles: Contents.IModel[] = [];
3737
constructor(
38-
private connInfo: IConnection,
38+
private connInfo: IJupyterConnection,
3939
private serverSettings: ServerConnection.ISettings,
4040
kernelSpec: IJupyterKernelSpec | LiveKernelModel | undefined,
4141
private sessionManager: SessionManager,

src/client/datascience/jupyter/jupyterSessionManager.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { IConfigurationService, IOutputChannel } from '../../common/types';
1010
import * as localize from '../../common/utils/localize';
1111
import { noop } from '../../common/utils/misc';
1212
import {
13-
IConnection,
13+
IJupyterConnection,
1414
IJupyterKernel,
1515
IJupyterKernelSpec,
1616
IJupyterPasswordConnect,
@@ -27,7 +27,7 @@ import { LiveKernelModel } from './kernels/types';
2727
export class JupyterSessionManager implements IJupyterSessionManager {
2828
private sessionManager: SessionManager | undefined;
2929
private contentsManager: ContentsManager | undefined;
30-
private connInfo: IConnection | undefined;
30+
private connInfo: IJupyterConnection | undefined;
3131
private serverSettings: ServerConnection.ISettings | undefined;
3232

3333
constructor(
@@ -71,11 +71,11 @@ export class JupyterSessionManager implements IJupyterSessionManager {
7171
}
7272
}
7373

74-
public getConnInfo(): IConnection {
74+
public getConnInfo(): IJupyterConnection {
7575
return this.connInfo!;
7676
}
7777

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

190-
private async getServerConnectSettings(connInfo: IConnection): Promise<ServerConnection.ISettings> {
190+
private async getServerConnectSettings(connInfo: IJupyterConnection): Promise<ServerConnection.ISettings> {
191191
let serverSettings: Partial<ServerConnection.ISettings> = {
192192
baseUrl: connInfo.baseUrl,
193193
appUrl: '',

src/client/datascience/jupyter/jupyterSessionManagerFactory.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ import { inject, injectable, named } from 'inversify';
55

66
import { IConfigurationService, IOutputChannel } from '../../common/types';
77
import { JUPYTER_OUTPUT_CHANNEL } from '../constants';
8-
import { IConnection, IJupyterPasswordConnect, IJupyterSessionManager, IJupyterSessionManagerFactory } from '../types';
8+
import {
9+
IJupyterConnection,
10+
IJupyterPasswordConnect,
11+
IJupyterSessionManager,
12+
IJupyterSessionManagerFactory
13+
} from '../types';
914
import { JupyterSessionManager } from './jupyterSessionManager';
1015
import { KernelSelector } from './kernels/kernelSelector';
1116

@@ -23,7 +28,7 @@ export class JupyterSessionManagerFactory implements IJupyterSessionManagerFacto
2328
* @param connInfo - connection information to the server that's already running.
2429
* @param failOnPassword - whether or not to fail the creation if a password is required.
2530
*/
26-
public async create(connInfo: IConnection, failOnPassword?: boolean): Promise<IJupyterSessionManager> {
31+
public async create(connInfo: IJupyterConnection, failOnPassword?: boolean): Promise<IJupyterSessionManager> {
2732
const result = new JupyterSessionManager(
2833
this.jupyterPasswordConnect,
2934
this.config,

src/client/datascience/jupyter/jupyterUtils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { IDataScienceSettings } from '../../common/types';
1111
import { noop } from '../../common/utils/misc';
1212
import { SystemVariables } from '../../common/variables/systemVariables';
1313
import { getJupyterConnectionDisplayName } from '../jupyter/jupyterConnection';
14-
import { IConnection } from '../types';
14+
import { IJupyterConnection } from '../types';
1515

1616
export function expandWorkingDir(
1717
workingDir: string | undefined,
@@ -27,7 +27,7 @@ export function expandWorkingDir(
2727
return path.dirname(launchingFile);
2828
}
2929

30-
export function createRemoteConnectionInfo(uri: string, settings: IDataScienceSettings): IConnection {
30+
export function createRemoteConnectionInfo(uri: string, settings: IDataScienceSettings): IJupyterConnection {
3131
let url: URL;
3232
try {
3333
url = new URL(uri);

src/client/datascience/jupyter/kernels/kernelSwitcher.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { Common, DataScience } from '../../../common/utils/localize';
1111
import { StopWatch } from '../../../common/utils/stopWatch';
1212
import { JupyterSessionStartError } from '../../baseJupyterSession';
1313
import { Commands, Settings } from '../../constants';
14-
import { IConnection, IJupyterKernelSpec, IJupyterSessionManagerFactory, INotebook } from '../../types';
14+
import { IJupyterConnection, IJupyterKernelSpec, IJupyterSessionManagerFactory, INotebook } from '../../types';
1515
import { JupyterInvalidKernelError } from '../jupyterInvalidKernelError';
1616
import { KernelSelector, KernelSpecInterpreter } from './kernelSelector';
1717
import { LiveKernelModel } from './types';
@@ -60,10 +60,8 @@ export class KernelSwitcher {
6060
} else if (notebook) {
6161
const connInfo = notebook.connection;
6262
const currentKernel = notebook.getKernelSpec();
63-
if (connInfo) {
64-
// Remote connection is always jupyter connection
65-
const jupyterConnInfo = connInfo as IConnection;
66-
kernel = await this.selectRemoteJupyterKernel(notebook.resource, jupyterConnInfo, currentKernel);
63+
if (connInfo && connInfo.type === 'jupyter') {
64+
kernel = await this.selectRemoteJupyterKernel(notebook.resource, connInfo, currentKernel);
6765
}
6866
}
6967
return kernel;
@@ -78,7 +76,7 @@ export class KernelSwitcher {
7876

7977
private async selectRemoteJupyterKernel(
8078
resource: Resource,
81-
connInfo: IConnection,
79+
connInfo: IJupyterConnection,
8280
currentKernel?: IJupyterKernelSpec | LiveKernelModel
8381
): Promise<KernelSpecInterpreter> {
8482
const stopWatch = new StopWatch();

src/client/datascience/jupyter/liveshare/guestJupyterExecution.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import * as localize from '../../../common/utils/localize';
1717
import { IInterpreterService, PythonInterpreter } from '../../../interpreter/contracts';
1818
import { IServiceContainer } from '../../../ioc/types';
1919
import { LiveShare, LiveShareCommands } from '../../constants';
20-
import { IConnection, INotebookServer, INotebookServerOptions } from '../../types';
20+
import { IJupyterConnection, INotebookServer, INotebookServerOptions } from '../../types';
2121
import { JupyterConnectError } from '../jupyterConnectError';
2222
import { JupyterExecutionBase } from '../jupyterExecution';
2323
import { KernelSelector } from '../kernels/kernelSelector';
@@ -87,7 +87,7 @@ export class GuestJupyterExecution extends LiveShareParticipantGuest(
8787
const service = await this.waitForService();
8888
if (service) {
8989
const purpose = options ? options.purpose : uuid();
90-
const connection: IConnection = await service.request(
90+
const connection: IJupyterConnection = await service.request(
9191
LiveShareCommands.connectToNotebookServer,
9292
[options],
9393
cancelToken

src/client/datascience/jupyter/liveshare/guestJupyterServer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import * as localize from '../../../common/utils/localize';
1212
import { IServiceContainer } from '../../../ioc/types';
1313
import { LiveShare, LiveShareCommands } from '../../constants';
1414
import {
15-
IConnection,
1615
IDataScience,
16+
IJupyterConnection,
1717
IJupyterSessionManagerFactory,
1818
INotebook,
1919
INotebookServer,
@@ -118,7 +118,7 @@ export class GuestJupyterServer
118118
}
119119

120120
// Return a copy of the connection information that this server used to connect with
121-
public getConnectionInfo(): IConnection | undefined {
121+
public getConnectionInfo(): IJupyterConnection | undefined {
122122
if (this.launchInfo) {
123123
return this.launchInfo.connectionInfo;
124124
}

0 commit comments

Comments
 (0)