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 remote Kernel finder provider #14101

Merged
merged 2 commits into from
Aug 11, 2023
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
2 changes: 1 addition & 1 deletion src/kernels/internalTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export enum ContributedKernelFinderKind {
}

export interface IContributedKernelFinder<T extends KernelConnectionMetadata = KernelConnectionMetadata> {
status: 'discovering' | 'idle';
readonly status: 'discovering' | 'idle';
onDidChangeStatus: Event<void>;
DonJayamanne marked this conversation as resolved.
Show resolved Hide resolved
/**
* Last error thrown when listing the kernels.
Expand Down
26 changes: 18 additions & 8 deletions src/kernels/jupyter/finder/remoteKernelFinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ export class RemoteKernelFinder implements IRemoteKernelFinder, IDisposable {
removed?: { id: string }[];
}>();
onDidChangeKernels = this._onDidChangeKernels.event;
private readonly _onDidChange = new EventEmitter<void>();
DonJayamanne marked this conversation as resolved.
Show resolved Hide resolved
onDidChange = this._onDidChange.event;
DonJayamanne marked this conversation as resolved.
Show resolved Hide resolved

private readonly disposables: IDisposable[] = [];

Expand All @@ -87,6 +89,20 @@ export class RemoteKernelFinder implements IRemoteKernelFinder, IDisposable {

private readonly cacheKey: string;
private readonly cacheFile: Uri;

/**
*
* Remote kernel finder is resource agnostic.
*/
public get kernels(): RemoteKernelConnectionMetadata[] {
return this.cache;
}
get items(): RemoteKernelConnectionMetadata[] {
return this.kernels;
}
get title(): string {
return this.displayName;
}
constructor(
readonly id: string,
readonly displayName: string,
Expand All @@ -106,7 +122,9 @@ export class RemoteKernelFinder implements IRemoteKernelFinder, IDisposable {
// Unlike the Local kernel finder universal remote kernel finders will be added on the fly
this.disposables.push(kernelFinder.registerKernelFinder(this));

this._onDidChangeKernels.event(() => this._onDidChange.fire(), this, this.disposables);
this.disposables.push(this._onDidChangeKernels);
this.disposables.push(this._onDidChange);
this.disposables.push(this._onDidChangeStatus);
this.disposables.push(this.promiseMonitor);
}
Expand Down Expand Up @@ -246,14 +264,6 @@ export class RemoteKernelFinder implements IRemoteKernelFinder, IDisposable {
await promise;
}

/**
*
* Remote kernel finder is resource agnostic.
*/
public get kernels(): RemoteKernelConnectionMetadata[] {
return this.cache;
}

private async getRemoteConnectionInfo(displayProgress: boolean = true): Promise<IJupyterConnection | undefined> {
const disposables: IDisposable[] = [];
if (displayProgress) {
Expand Down
5 changes: 4 additions & 1 deletion src/kernels/jupyter/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
import { ClassType } from '../../platform/ioc/types';
import { ContributedKernelFinderKind, IContributedKernelFinder } from '../internalTypes';
import { IJupyterServerUri, IJupyterUriProvider, JupyterServerCollection } from '../../api';
import { IQuickPickItemProvider } from '../../platform/common/providerBasedQuickPick';

export type JupyterServerInfo = {
base_url: string;
Expand Down Expand Up @@ -290,7 +291,9 @@ export interface IJupyterRemoteCachedKernelValidator {
isValid(kernel: LiveRemoteKernelConnectionMetadata): Promise<boolean>;
}

export interface IRemoteKernelFinder extends IContributedKernelFinder<RemoteKernelConnectionMetadata> {
export interface IRemoteKernelFinder
extends IContributedKernelFinder<RemoteKernelConnectionMetadata>,
IQuickPickItemProvider<RemoteKernelConnectionMetadata> {
kind: ContributedKernelFinderKind.Remote;
serverProviderHandle: JupyterServerProviderHandle;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import { IConnectionDisplayDataProvider, IRemoteNotebookKernelSourceSelector } f
import { MultiStepResult } from './types';
import { JupyterConnection } from '../../../kernels/jupyter/connection/jupyterConnection';
import { generateIdFromRemoteProvider } from '../../../kernels/jupyter/jupyterUtils';
import { BaseProviderBasedQuickPick, IQuickPickItemProvider } from '../../../platform/common/providerBasedQuickPick';
import { BaseProviderBasedQuickPick } from '../../../platform/common/providerBasedQuickPick';
import { PreferredKernelConnectionService } from '../preferredKernelConnectionService';
import { traceError } from '../../../platform/logging';

Expand Down Expand Up @@ -227,7 +227,7 @@ export class RemoteNotebookKernelSourceSelector implements IRemoteNotebookKernel
case KernelFinderEntityQuickPickType.KernelFinder:
const result = await this.selectRemoteKernelFromPicker(
state.notebook,
Promise.resolve(selectedSource.kernelFinderInfo),
Promise.resolve(selectedSource.kernelFinderInfo as IRemoteKernelFinder),
token
).catch((ex) => traceError(`Failed to select a kernel`, ex));
if (result && result === InputFlowAction.back) {
Expand Down Expand Up @@ -295,15 +295,15 @@ export class RemoteNotebookKernelSourceSelector implements IRemoteNotebookKernel
throw new CancellationError();
}
// Wait for the remote provider to be registered.
return new Promise<IContributedKernelFinder>((resolve) => {
return new Promise<IRemoteKernelFinder>((resolve) => {
const found = this.kernelFinder.registered.find(
(f) =>
f.kind === 'remote' &&
(f as IRemoteKernelFinder).serverProviderHandle.id === serverId.id &&
(f as IRemoteKernelFinder).serverProviderHandle.handle === serverId.handle
);
if (found) {
return resolve(found);
return resolve(found as IRemoteKernelFinder);
}
this.kernelFinder.onDidChangeRegistrations(
(e) => {
Expand All @@ -314,7 +314,7 @@ export class RemoteNotebookKernelSourceSelector implements IRemoteNotebookKernel
(f as IRemoteKernelFinder).serverProviderHandle.handle === serverId.handle
);
if (found) {
return resolve(found);
return resolve(found as IRemoteKernelFinder);
}
},
this,
Expand All @@ -337,25 +337,9 @@ export class RemoteNotebookKernelSourceSelector implements IRemoteNotebookKernel
}
private async selectRemoteKernelFromPicker(
notebook: NotebookDocument,
source: Promise<IContributedKernelFinder<KernelConnectionMetadata>>,
source: Promise<IRemoteKernelFinder>,
token: CancellationToken
) {
const provider = source.then((source) => {
const onDidChangeEvent = new EventEmitter<void>();
source.onDidChangeKernels(() => onDidChangeEvent.fire());
return <IQuickPickItemProvider<KernelConnectionMetadata>>{
title: DataScience.kernelPickerSelectKernelFromRemoteTitle(source.displayName),
get items() {
return source.kernels;
},
get status() {
return source.status;
},
onDidChange: onDidChangeEvent.event,
onDidChangeStatus: source.onDidChangeStatus,
refresh: () => source.refresh()
};
});
const quickPickFactory = (item: KernelConnectionMetadata) => {
const displayData = this.displayDataProvider.getDisplayData(item);
return <QuickPickItem>{
Expand All @@ -369,7 +353,7 @@ export class RemoteNotebookKernelSourceSelector implements IRemoteNotebookKernel
label: this.displayDataProvider.getDisplayData(item).category || 'Other'
};
};
const remoteKernelPicker = new BaseProviderBasedQuickPick(provider, quickPickFactory, getCategory, {
const remoteKernelPicker = new BaseProviderBasedQuickPick(source, quickPickFactory, getCategory, {
supportsBack: true
});
const preferred = new PreferredKernelConnectionService(this.jupyterConnection);
Expand Down
Loading