Skip to content

Commit

Permalink
Switch to remote session instead of switching kernels (#9147)
Browse files Browse the repository at this point in the history
For #8866
When selecting a remote session, connect to that session instead of connecting to that kernel.
If we connect to a kernel, the API shutdowns the previously connected kernel.

With the new changes, when selecting a remote kernel, we're in-fact selecting a remote session that we connect to.
However the API is still indicates we're connecting to a kernel (however under the hoods we connect to a session).
  • Loading branch information
DonJayamanne committed Dec 17, 2019
1 parent 13f19d1 commit 98b31c9
Show file tree
Hide file tree
Showing 17 changed files with 599 additions and 351 deletions.
62 changes: 37 additions & 25 deletions src/client/datascience/datascience.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,16 @@ import { PYTHON_ALLFILES, PYTHON_LANGUAGE } from '../common/constants';
import { ContextKey } from '../common/contextKey';
import '../common/extensions';
import { traceError } from '../common/logger';
import { BANNER_NAME_DS_SURVEY, GLOBAL_MEMENTO, IConfigurationService, IDisposable, IDisposableRegistry, IExtensionContext, IMemento, IPythonExtensionBanner } from '../common/types';
import {
BANNER_NAME_DS_SURVEY,
GLOBAL_MEMENTO,
IConfigurationService,
IDisposable,
IDisposableRegistry,
IExtensionContext,
IMemento,
IPythonExtensionBanner
} from '../common/types';
import { waitForPromise } from '../common/utils/async';
import { debounceAsync, swallowExceptions } from '../common/utils/decorators';
import * as localize from '../common/utils/localize';
Expand All @@ -22,7 +31,17 @@ import { hasCells } from './cellFactory';
import { Commands, EditorContexts, Settings, Telemetry } from './constants';
import { createRemoteConnectionInfo } from './jupyter/jupyterUtils';
import { KernelSelector, KernelSpecInterpreter } from './jupyter/kernels/kernelSelector';
import { ICodeWatcher, IConnection, IDataScience, IDataScienceCodeLensProvider, IDataScienceCommandListener, IJupyterKernel, IJupyterKernelSpec, IJupyterSessionManagerFactory, INotebookEditorProvider } from './types';
import { LiveKernelModel } from './jupyter/kernels/types';
import {
ICodeWatcher,
IConnection,
IDataScience,
IDataScienceCodeLensProvider,
IDataScienceCommandListener,
IJupyterKernelSpec,
IJupyterSessionManagerFactory,
INotebookEditorProvider
} from './types';

interface ISelectUriQuickPickItem extends vscode.QuickPickItem {
newChoice: boolean;
Expand All @@ -36,7 +55,8 @@ export class DataScience implements IDataScience {
private startTime: number = Date.now();
private localLabel = `$(zap) ${localize.DataScience.jupyterSelectURILocalLabel()}`;
private newLabel = `$(server) ${localize.DataScience.jupyterSelectURINewLabel()}`;
constructor(@inject(IServiceContainer) private serviceContainer: IServiceContainer,
constructor(
@inject(IServiceContainer) private serviceContainer: IServiceContainer,
@inject(ICommandManager) private commandManager: ICommandManager,
@inject(IDisposableRegistry) private disposableRegistry: IDisposableRegistry,
@inject(IExtensionContext) private extensionContext: IExtensionContext,
Expand All @@ -62,11 +82,7 @@ export class DataScience implements IDataScience {
public async activate(): Promise<void> {
this.registerCommands();

this.extensionContext.subscriptions.push(
vscode.languages.registerCodeLensProvider(
PYTHON_ALLFILES, this.dataScienceCodeLensProvider
)
);
this.extensionContext.subscriptions.push(vscode.languages.registerCodeLensProvider(PYTHON_ALLFILES, this.dataScienceCodeLensProvider));

// Set our initial settings and sign up for changes
this.onSettingsChanged();
Expand Down Expand Up @@ -227,12 +243,12 @@ export class DataScience implements IDataScience {
}

@captureTelemetry(Telemetry.SelectLocalJupyterKernel)
public async selectLocalJupyterKernel(currentKernel?: IJupyterKernelSpec | IJupyterKernel & Partial<IJupyterKernelSpec>): Promise<KernelSpecInterpreter> {
public async selectLocalJupyterKernel(currentKernel?: IJupyterKernelSpec | LiveKernelModel): Promise<KernelSpecInterpreter> {
return this.kernelSelector.selectLocalKernel(undefined, undefined, currentKernel);
}

@captureTelemetry(Telemetry.SelectRemoteJupyuterKernel)
public async selectRemoteJupyterKernel(connInfo: IConnection, currentKernel?: IJupyterKernelSpec | IJupyterKernel & Partial<IJupyterKernelSpec>): Promise<KernelSpecInterpreter> {
public async selectRemoteJupyterKernel(connInfo: IConnection, currentKernel?: IJupyterKernelSpec | LiveKernelModel): Promise<KernelSpecInterpreter> {
const session = await this.jupyterSessionManagerFactory.create(connInfo);
return this.kernelSelector.selectRemoteKernel(session, undefined, currentKernel);
}
Expand Down Expand Up @@ -292,10 +308,7 @@ export class DataScience implements IDataScience {
}
}

private async startSelectingURI(
input: IMultiStepInput<{}>,
_state: {}): Promise<InputStep<{}> | void> {

private async startSelectingURI(input: IMultiStepInput<{}>, _state: {}): Promise<InputStep<{}> | void> {
// First step, show a quick pick to choose either the remote or the local.
// newChoice element will be set if the user picked 'enter a new server'
const item = await input.showQuickPick<ISelectUriQuickPickItem, IQuickPickParameters<ISelectUriQuickPickItem>>({
Expand All @@ -312,9 +325,7 @@ export class DataScience implements IDataScience {
}
}

private async selectRemoteURI(
input: IMultiStepInput<{}>,
_state: {}): Promise<InputStep<{}> | void> {
private async selectRemoteURI(input: IMultiStepInput<{}>, _state: {}): Promise<InputStep<{}> | void> {
// Ask the user to enter a URI to connect to.
const uri = await input.showInputBox({
title: localize.DataScience.jupyterSelectURIPrompt(),
Expand Down Expand Up @@ -354,12 +365,14 @@ export class DataScience implements IDataScience {
const sessionManager = await waitForPromise(this.jupyterSessionManagerFactory.create(connection, true), 2000);
if (sessionManager) {
const kernels = await sessionManager.getRunningKernels();
const lastActiveTime = kernels.map(k => k.lastActivityTime).reduce((p, c) => {
if (!p || c > p) {
return c;
}
return p;
});
const lastActiveTime = kernels
.map(k => k.lastActivityTime)
.reduce((p, c) => {
if (!p || c > p) {
return c;
}
return p;
});
const activeConnectCount = kernels.map(k => k.numberOfConnections).reduce((p, c) => p + c);
return {
label: uri,
Expand Down Expand Up @@ -439,8 +452,7 @@ export class DataScience implements IDataScience {
if (activeEditor && activeCodeWatcher) {
// Find the cell that matches
return activeCodeWatcher.getCodeLenses().find((c: vscode.CodeLens) => {
if (c.range.end.line >= activeEditor.selection.anchor.line &&
c.range.start.line <= activeEditor.selection.anchor.line) {
if (c.range.end.line >= activeEditor.selection.anchor.line && c.range.start.line <= activeEditor.selection.anchor.line) {
return true;
}
return false;
Expand Down
Loading

0 comments on commit 98b31c9

Please sign in to comment.