Skip to content
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

Remove ServerConnectionType. #11913

Merged
merged 1 commit into from
Nov 4, 2022
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
12 changes: 3 additions & 9 deletions src/kernels/jupyter/finder/remoteKernelFinder.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,7 @@ import { JupyterSessionManager } from '../session/jupyterSessionManager';
import { JupyterSessionManagerFactory } from '../session/jupyterSessionManagerFactory';
import { ILocalKernelFinder } from '../../raw/types';
import { ActiveKernelIdList, PreferredRemoteKernelIdProvider } from '../preferredRemoteKernelIdProvider';
import {
IJupyterKernel,
IJupyterRemoteCachedKernelValidator,
IJupyterSessionManager,
IServerConnectionType
} from '../types';
import { IJupyterKernel, IJupyterRemoteCachedKernelValidator, IJupyterSessionManager } from '../types';
import { KernelFinder } from '../../kernelFinder';
import { NotebookProvider } from '../launcher/notebookProvider';
import { PythonExtensionChecker } from '../../../platform/api/pythonApi';
Expand Down Expand Up @@ -160,11 +155,10 @@ suite(`Remote Kernel Finder`, () => {
};
when(serverUriStorage.getUri()).thenResolve(serverEntry);
when(serverUriStorage.getRemoteUri()).thenResolve(serverEntry);
const connectionType = mock<IServerConnectionType>();
when(connectionType.isLocalLaunch).thenReturn(false);
when(serverUriStorage.isLocalLaunch).thenReturn(false);
const onDidChangeEvent = new EventEmitter<void>();
disposables.push(onDidChangeEvent);
when(connectionType.onDidChange).thenReturn(onDidChangeEvent.event);
when(serverUriStorage.onDidChangeConnectionType).thenReturn(onDidChangeEvent.event);
cachedRemoteKernelValidator = mock<IJupyterRemoteCachedKernelValidator>();
when(cachedRemoteKernelValidator.isValid(anything())).thenResolve(true);
const env = mock<IApplicationEnvironment>();
Expand Down
6 changes: 2 additions & 4 deletions src/kernels/jupyter/jupyterConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ import {
IJupyterServerUriStorage,
IJupyterSessionManager,
IJupyterSessionManagerFactory,
IJupyterUriProviderRegistration,
IServerConnectionType
IJupyterUriProviderRegistration
} from './types';

/**
Expand All @@ -37,13 +36,12 @@ export class JupyterConnection implements IExtensionSyncActivationService {
private readonly jupyterSessionManagerFactory: IJupyterSessionManagerFactory,
@inject(IDisposableRegistry)
private readonly disposables: IDisposableRegistry,
@inject(IServerConnectionType) private readonly serverConnectionType: IServerConnectionType,
@inject(IJupyterServerUriStorage) private readonly serverUriStorage: IJupyterServerUriStorage
) {
disposables.push(this);
}
public activate() {
this.serverConnectionType.onDidChange(
this.serverUriStorage.onDidChangeConnectionType(
() =>
// When server URI changes, clear our pending URI timeouts
this.clearTimeouts(),
Expand Down
6 changes: 3 additions & 3 deletions src/kernels/jupyter/launcher/notebookProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
import { Cancellation } from '../../../platform/common/cancellation';
import { DisplayOptions } from '../../displayOptions';
import { IRawNotebookProvider } from '../../raw/types';
import { IJupyterNotebookProvider, IServerConnectionType } from '../types';
import { IJupyterNotebookProvider, IJupyterServerUriStorage } from '../types';

/**
* Generic class for connecting to a server. Probably could be renamed as it doesn't provide notebooks, but rather connections.
Expand All @@ -32,7 +32,7 @@ export class NotebookProvider implements INotebookProvider {
@inject(IJupyterNotebookProvider)
private readonly jupyterNotebookProvider: IJupyterNotebookProvider,
@inject(IPythonExtensionChecker) private readonly extensionChecker: IPythonExtensionChecker,
@inject(IServerConnectionType) private readonly serverConnectionType: IServerConnectionType
@inject(IJupyterServerUriStorage) private readonly uriStorage: IJupyterServerUriStorage
) {}

// Attempt to connect to our server provider, and if we do, return the connection info
Expand All @@ -49,7 +49,7 @@ export class NotebookProvider implements INotebookProvider {
options.ui = this.startupUi;
if (this.rawNotebookProvider?.isSupported && options.localJupyter) {
throw new Error('Connect method should not be invoked for local Connections when Raw is supported');
} else if (this.extensionChecker.isPythonExtensionInstalled || !this.serverConnectionType.isLocalLaunch) {
} else if (this.extensionChecker.isPythonExtensionInstalled || !this.uriStorage.isLocalLaunch) {
return this.jupyterNotebookProvider.connect(options).finally(() => handler.dispose());
} else {
handler.dispose();
Expand Down
12 changes: 2 additions & 10 deletions src/kernels/jupyter/launcher/serverUriStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,7 @@ import {
} from '../../../platform/common/types';
import { traceError, traceInfoIfCI, traceVerbose } from '../../../platform/logging';
import { computeServerId, extractJupyterServerHandleAndId } from '../jupyterUtils';
import {
IJupyterServerUriEntry,
IJupyterServerUriStorage,
IJupyterUriProviderRegistration,
IServerConnectionType
} from '../types';
import { IJupyterServerUriEntry, IJupyterServerUriStorage, IJupyterUriProviderRegistration } from '../types';

export const mementoKeyToIndicateIfConnectingToLocalKernelsOnly = 'connectToLocalKernelsOnly';
export const currentServerHashKey = 'currentServerHash';
Expand All @@ -33,7 +28,7 @@ export const currentServerHashKey = 'currentServerHash';
* Class for storing Jupyter Server URI values
*/
@injectable()
export class JupyterServerUriStorage implements IJupyterServerUriStorage, IServerConnectionType {
export class JupyterServerUriStorage implements IJupyterServerUriStorage {
private lastSavedList?: Promise<IJupyterServerUriEntry[]>;
private currentUriPromise: Promise<IJupyterServerUriEntry | undefined> | undefined;
private _currentServerId: string | undefined;
Expand All @@ -53,9 +48,6 @@ export class JupyterServerUriStorage implements IJupyterServerUriStorage, IServe
public get currentServerId(): string | undefined {
return this._currentServerId;
}
public get onDidChange(): Event<void> {
return this._onDidChangeUri.event;
}
public get onDidChangeConnectionType(): Event<void> {
return this._onDidChangeUri.event;
}
Expand Down
4 changes: 1 addition & 3 deletions src/kernels/jupyter/serviceRegistry.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ import {
IJupyterRequestAgentCreator,
INotebookServerFactory,
ILiveRemoteKernelConnectionUsageTracker,
IJupyterRemoteCachedKernelValidator,
IServerConnectionType
IJupyterRemoteCachedKernelValidator
} from './types';
import { IJupyterCommandFactory, IJupyterSubCommandExecutionService } from './types.node';
import { UniversalRemoteKernelFinderController } from './finder/universalRemoteKernelFinderController';
Expand Down Expand Up @@ -127,7 +126,6 @@ export function registerTypes(serviceManager: IServiceManager, _isDevMode: boole
JupyterUriProviderRegistration
);
serviceManager.addSingleton<IJupyterServerUriStorage>(IJupyterServerUriStorage, JupyterServerUriStorage);
serviceManager.addBinding(IJupyterServerUriStorage, IServerConnectionType);
serviceManager.addSingleton<INotebookStarter>(INotebookStarter, NotebookStarter);
serviceManager.addSingleton<INotebookProvider>(INotebookProvider, NotebookProvider);
serviceManager.addSingleton<IJupyterBackingFileCreator>(IJupyterBackingFileCreator, BackingFileCreator);
Expand Down
4 changes: 1 addition & 3 deletions src/kernels/jupyter/serviceRegistry.web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ import {
IJupyterRequestCreator,
INotebookServerFactory,
ILiveRemoteKernelConnectionUsageTracker,
IJupyterRemoteCachedKernelValidator,
IServerConnectionType
IJupyterRemoteCachedKernelValidator
} from './types';
import { CellOutputMimeTypeTracker } from './jupyterCellOutputMimeTypeTracker';
import { UniversalRemoteKernelFinderController } from './finder/universalRemoteKernelFinderController';
Expand All @@ -60,7 +59,6 @@ export function registerTypes(serviceManager: IServiceManager, _isDevMode: boole
JupyterUriProviderRegistration
);
serviceManager.addSingleton<IJupyterServerUriStorage>(IJupyterServerUriStorage, JupyterServerUriStorage);
serviceManager.addBinding(IJupyterServerUriStorage, IServerConnectionType);
serviceManager.addSingleton<INotebookProvider>(INotebookProvider, NotebookProvider);
serviceManager.addSingleton<IJupyterBackingFileCreator>(IJupyterBackingFileCreator, BackingFileCreator);
serviceManager.addSingleton<IExtensionSingleActivationService>(IExtensionSingleActivationService, CommandRegistry);
Expand Down
7 changes: 0 additions & 7 deletions src/kernels/jupyter/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,11 +360,4 @@ export interface IJupyterRemoteCachedKernelValidator {
isValid(kernel: LiveRemoteKernelConnectionMetadata): Promise<boolean>;
}

export const IServerConnectionType = Symbol('IServerConnectionType');

export interface IServerConnectionType {
isLocalLaunch: boolean;
onDidChange: Event<void>;
}

export interface IRemoteKernelFinder extends IContributedKernelFinder<RemoteKernelConnectionMetadata> {}
8 changes: 4 additions & 4 deletions src/kernels/raw/finder/localKernelFinder.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import { PythonExtensionChecker } from '../../../platform/api/pythonApi';
import { KernelFinder } from '../../../kernels/kernelFinder';
import { PreferredRemoteKernelIdProvider } from '../../../kernels/jupyter/preferredRemoteKernelIdProvider';
import { UniversalRemoteKernelFinder } from '../../../kernels/jupyter/finder/universalRemoteKernelFinder';
import { IServerConnectionType } from '../../../kernels/jupyter/types';
import { IJupyterServerUriStorage } from '../../../kernels/jupyter/types';
import { IPythonExecutionFactory, IPythonExecutionService } from '../../../platform/common/process/types.node';
import { getUserHomeDir } from '../../../platform/common/utils/platform.node';
import { IApplicationEnvironment } from '../../../platform/common/application/types';
Expand Down Expand Up @@ -249,11 +249,11 @@ import { createEventHandler, TestEventHandler } from '../../../test/common';
when(memento.update('JUPYTER_GLOBAL_KERNELSPECS_V2', anything())).thenResolve();

preferredRemote = mock(PreferredRemoteKernelIdProvider);
const connectionType = mock<IServerConnectionType>();
when(connectionType.isLocalLaunch).thenReturn(true);
const uriStorage = mock<IJupyterServerUriStorage>();
when(uriStorage.isLocalLaunch).thenReturn(true);
const onDidChangeEvent = new EventEmitter<void>();
disposables.push(onDidChangeEvent);
when(connectionType.onDidChange).thenReturn(onDidChangeEvent.event);
when(uriStorage.onDidChangeConnectionType).thenReturn(onDidChangeEvent.event);

const extensions = mock<IExtensions>();
kernelFinder = new KernelFinder([]);
Expand Down
6 changes: 3 additions & 3 deletions src/notebooks/controllers/controllerDefaultService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { inject, injectable } from 'inversify';
import { NotebookDocument } from 'vscode';
import { isPythonNotebook } from '../../kernels/helpers';
import { PreferredRemoteKernelIdProvider } from '../../kernels/jupyter/preferredRemoteKernelIdProvider';
import { IServerConnectionType } from '../../kernels/jupyter/types';
import { IJupyterServerUriStorage } from '../../kernels/jupyter/types';
import { IVSCodeNotebook } from '../../platform/common/application/types';
import { InteractiveWindowView, JupyterNotebookView, PYTHON_LANGUAGE } from '../../platform/common/constants';
import { IDisposableRegistry, IsWebExtension, Resource } from '../../platform/common/types';
Expand All @@ -27,15 +27,15 @@ import {
@injectable()
export class ControllerDefaultService implements IControllerDefaultService {
private get isLocalLaunch(): boolean {
return this.serverConnectionType.isLocalLaunch;
return this.serverUriStorage.isLocalLaunch;
}
constructor(
@inject(IControllerRegistration) private readonly registration: IControllerRegistration,
@inject(IControllerLoader) private readonly loader: IControllerLoader,
@inject(IInterpreterService) private readonly interpreters: IInterpreterService,
@inject(IVSCodeNotebook) private readonly notebook: IVSCodeNotebook,
@inject(IDisposableRegistry) readonly disposables: IDisposableRegistry,
@inject(IServerConnectionType) private readonly serverConnectionType: IServerConnectionType,
@inject(IJupyterServerUriStorage) private readonly serverUriStorage: IJupyterServerUriStorage,
@inject(PreferredRemoteKernelIdProvider)
private readonly preferredRemoteFinder: PreferredRemoteKernelIdProvider,
@inject(IsWebExtension) private readonly isWeb: boolean
Expand Down
6 changes: 3 additions & 3 deletions src/notebooks/controllers/controllerPreferredService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
workspace
} from 'vscode';
import { getKernelConnectionLanguage, getLanguageInNotebookMetadata, isPythonNotebook } from '../../kernels/helpers';
import { IServerConnectionType } from '../../kernels/jupyter/types';
import { IJupyterServerUriStorage } from '../../kernels/jupyter/types';
import { trackKernelResourceInformation } from '../../kernels/telemetry/helper';
import { KernelConnectionMetadata } from '../../kernels/types';
import { IExtensionSyncActivationService } from '../../platform/activation/types';
Expand Down Expand Up @@ -63,7 +63,7 @@ export class ControllerPreferredService implements IControllerPreferredService,
private preferredControllers = new WeakMap<NotebookDocument, IVSCodeNotebookController>();
private preferredCancelTokens = new WeakMap<NotebookDocument, CancellationTokenSource>();
private get isLocalLaunch(): boolean {
return this.serverConnectionType.isLocalLaunch;
return this.serverUriStorage.isLocalLaunch;
}
private disposables = new Set<IDisposable>();
constructor(
Expand All @@ -74,7 +74,7 @@ export class ControllerPreferredService implements IControllerPreferredService,
@inject(IVSCodeNotebook) private readonly notebook: IVSCodeNotebook,
@inject(IDisposableRegistry) disposables: IDisposableRegistry,
@inject(IPythonExtensionChecker) private readonly extensionChecker: IPythonExtensionChecker,
@inject(IServerConnectionType) private readonly serverConnectionType: IServerConnectionType,
@inject(IJupyterServerUriStorage) private readonly serverUriStorage: IJupyterServerUriStorage,
@inject(IKernelRankingHelper) private readonly kernelRankHelper: IKernelRankingHelper,
@inject(IControllerSelection) private readonly selection: IControllerSelection
) {
Expand Down
5 changes: 2 additions & 3 deletions src/notebooks/controllers/controllerRegistration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { inject, injectable } from 'inversify';
import { Event, EventEmitter } from 'vscode';
import { getDisplayNameOrNameOfKernelConnection } from '../../kernels/helpers';
import { computeServerId } from '../../kernels/jupyter/jupyterUtils';
import { IJupyterServerUriEntry, IJupyterServerUriStorage, IServerConnectionType } from '../../kernels/jupyter/types';
import { IJupyterServerUriEntry, IJupyterServerUriStorage } from '../../kernels/jupyter/types';
import { IKernelProvider, isRemoteConnection, KernelConnectionMetadata } from '../../kernels/types';
import { IPythonExtensionChecker } from '../../platform/api/types';
import {
Expand Down Expand Up @@ -79,12 +79,11 @@ export class ControllerRegistration implements IControllerRegistration {
@inject(IApplicationShell) private readonly appShell: IApplicationShell,
@inject(IBrowserService) private readonly browser: IBrowserService,
@inject(IServiceContainer) private readonly serviceContainer: IServiceContainer,
@inject(IServerConnectionType) private readonly serverConnectionType: IServerConnectionType,
@inject(IJupyterServerUriStorage) private readonly serverUriStorage: IJupyterServerUriStorage,
@inject(IPlatformService) private readonly platform: IPlatformService
) {
this.kernelFilter.onDidChange(this.onDidChangeFilter, this, this.disposables);
this.serverConnectionType.onDidChange(this.onDidChangeFilter, this, this.disposables);
this.serverUriStorage.onDidChangeConnectionType(this.onDidChangeFilter, this, this.disposables);
this.serverUriStorage.onDidChangeUri(this.onDidChangeUri, this, this.disposables);
this.serverUriStorage.onDidRemoveUris(this.onDidRemoveUris, this, this.disposables);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { PythonExtensionChecker } from '../../../platform/api/pythonApi';
import { IJupyterKernelConnectionSession, KernelConnectionMetadata } from '../../../kernels/types';
import { NotebookProvider } from '../../../kernels/jupyter/launcher/notebookProvider';
import { DisplayOptions } from '../../../kernels/displayOptions';
import { IJupyterNotebookProvider, IServerConnectionType } from '../../../kernels/jupyter/types';
import { IJupyterNotebookProvider, IJupyterServerUriStorage } from '../../../kernels/jupyter/types';
import { IRawNotebookProvider } from '../../../kernels/raw/types';
import { IDisposable } from '../../../platform/common/types';
import { disposeAllDisposables } from '../../../platform/common/helpers';
Expand All @@ -31,17 +31,17 @@ suite('NotebookProvider', () => {
when(rawNotebookProvider.isSupported).thenReturn(false);
const extensionChecker = mock(PythonExtensionChecker);
when(extensionChecker.isPythonExtensionInstalled).thenReturn(true);
const connectionType = mock<IServerConnectionType>();
when(connectionType.isLocalLaunch).thenReturn(true);
const uriStorage = mock<IJupyterServerUriStorage>();
when(uriStorage.isLocalLaunch).thenReturn(true);
const onDidChangeEvent = new vscode.EventEmitter<void>();
disposables.push(onDidChangeEvent);
when(connectionType.onDidChange).thenReturn(onDidChangeEvent.event);
when(uriStorage.onDidChangeConnectionType).thenReturn(onDidChangeEvent.event);

notebookProvider = new NotebookProvider(
instance(rawNotebookProvider),
instance(jupyterNotebookProvider),
instance(extensionChecker),
instance(connectionType)
instance(uriStorage)
);
});
teardown(() => disposeAllDisposables(disposables));
Expand Down
Loading