Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix forGetting an error on selecting an existing CI which has a display name from the historical CI's in the quick picks #13642

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 1 commit into from
Aug 28, 2020
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
1 change: 1 addition & 0 deletions news/2 Fixes/13387.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed connection to a Compute Instance from the quickpicks history options
10 changes: 6 additions & 4 deletions src/client/datascience/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,23 @@ const AllowedKeys = {
['execute_result']: new Set(Object.keys(dummyExecuteResultObj))
};

export function getSavedUriList(globalState: Memento): { uri: string; time: number }[] {
const uriList = globalState.get<{ uri: string; time: number }[]>(Settings.JupyterServerUriList);
export function getSavedUriList(globalState: Memento): { uri: string; time: number; displayName?: string }[] {
const uriList = globalState.get<{ uri: string; time: number; displayName?: string }[]>(
Settings.JupyterServerUriList
);
return uriList
? uriList.sort((a, b) => {
return b.time - a.time;
})
: [];
}
export function addToUriList(globalState: Memento, uri: string, time: number) {
export function addToUriList(globalState: Memento, uri: string, time: number, displayName: string) {
const uriList = getSavedUriList(globalState);

const editList = uriList.filter((f, i) => {
return f.uri !== uri && i < Settings.JupyterServerUriListMax - 1;
});
editList.splice(0, 0, { uri, time });
editList.splice(0, 0, { uri, time, displayName });

globalState.update(Settings.JupyterServerUriList, editList).then(noop, noop);
}
Expand Down
10 changes: 7 additions & 3 deletions src/client/datascience/interactive-common/interactiveBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { EXTENSION_ROOT_DIR, isTestExecution, PYTHON_LANGUAGE } from '../../comm
import { RemoveKernelToolbarInInteractiveWindow, RunByLine } from '../../common/experiments/groups';
import { traceError, traceInfo, traceWarning } from '../../common/logger';

import { isNil } from 'lodash';
import {
IConfigurationService,
IDisposableRegistry,
Expand Down Expand Up @@ -1168,10 +1169,13 @@ export abstract class InteractiveBase extends WebViewHost<IInteractiveWindowMapp
if (serverConnection.localLaunch) {
localizedUri = localize.DataScience.localJupyterServer();
} else {
localizedUri = serverConnection.displayName;

// Log this remote URI into our MRU list
addToUriList(this.globalStorage, localizedUri, Date.now());
addToUriList(
this.globalStorage,
!isNil(serverConnection.url) ? serverConnection.url : serverConnection.displayName,
Date.now(),
serverConnection.displayName
);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/client/datascience/jupyter/jupyterUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ export function createRemoteConnectionInfo(
},
dispose: noop,
rootDirectory: '',
getAuthHeader: serverUri ? () => getJupyterServerUri(uri)?.authorizationHeader : undefined
getAuthHeader: serverUri ? () => getJupyterServerUri(uri)?.authorizationHeader : undefined,
url: uri
};
}

Expand Down
9 changes: 6 additions & 3 deletions src/client/datascience/jupyter/serverSelector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
'use strict';

import { inject, injectable, named } from 'inversify';
import { isNil } from 'lodash';
import { ConfigurationTarget, Memento, QuickPickItem, Uri } from 'vscode';
import { IClipboard, ICommandManager } from '../../common/application/types';
import { GLOBAL_MEMENTO, IConfigurationService, IMemento } from '../../common/types';
Expand All @@ -26,6 +27,7 @@ const defaultUri = 'https://hostname:8080/?token=849d61a414abafab97bc4aab1f35477
interface ISelectUriQuickPickItem extends QuickPickItem {
newChoice: boolean;
provider?: IJupyterUriProvider;
url?: string;
}

@injectable()
Expand Down Expand Up @@ -66,7 +68,7 @@ export class JupyterServerSelector {
if (item.label === this.localLabel) {
await this.setJupyterURIToLocal();
} else if (!item.newChoice && !item.provider) {
await this.setJupyterURIToRemote(item.label);
await this.setJupyterURIToRemote(!isNil(item.url) ? item.url : item.label);
} else if (!item.provider) {
return this.selectRemoteURI.bind(this);
} else {
Expand Down Expand Up @@ -208,9 +210,10 @@ export class JupyterServerSelector {
if (uriItem.uri) {
const uriDate = new Date(uriItem.time);
items.push({
label: uriItem.uri,
label: !isNil(uriItem.displayName) ? uriItem.displayName : uriItem.uri,
detail: DataScience.jupyterSelectURIMRUDetail().format(uriDate.toLocaleString()),
newChoice: false
newChoice: false,
url: uriItem.uri
});
}
});
Expand Down
1 change: 1 addition & 0 deletions src/client/datascience/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export interface IJupyterConnection extends Disposable {
readonly hostName: string;
localProcExitCode: number | undefined;
readonly rootDirectory: string; // Directory where the notebook server was started.
readonly url?: string;
// tslint:disable-next-line: no-any
getAuthHeader?(): any; // Snould be a json object
}
Expand Down
8 changes: 4 additions & 4 deletions src/test/datascience/jupyter/serverSelector.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,31 +103,31 @@ suite('DataScience - Jupyter Server URI Selector', () => {

// Add in a new server
const serverA1 = { uri: 'ServerA', time: 1, date: new Date(1) };
addToUriList(mockStorage, serverA1.uri, serverA1.time);
addToUriList(mockStorage, serverA1.uri, serverA1.time, serverA1.uri);

await ds.selectJupyterURI(true);
assert.equal(quickPick?.items.length, 3, 'Wrong number of items in the quick pick');
quickPickCheck(quickPick?.items[2], serverA1);

// Add in a second server, the newer server should be higher in the list due to newer time
const serverB1 = { uri: 'ServerB', time: 2, date: new Date(2) };
addToUriList(mockStorage, serverB1.uri, serverB1.time);
addToUriList(mockStorage, serverB1.uri, serverB1.time, serverB1.uri);
await ds.selectJupyterURI(true);
assert.equal(quickPick?.items.length, 4, 'Wrong number of items in the quick pick');
quickPickCheck(quickPick?.items[2], serverB1);
quickPickCheck(quickPick?.items[3], serverA1);

// Reconnect to server A with a new time, it should now be higher in the list
const serverA3 = { uri: 'ServerA', time: 3, date: new Date(3) };
addToUriList(mockStorage, serverA3.uri, serverA3.time);
addToUriList(mockStorage, serverA3.uri, serverA3.time, serverA3.uri);
await ds.selectJupyterURI(true);
assert.equal(quickPick?.items.length, 4, 'Wrong number of items in the quick pick');
quickPickCheck(quickPick?.items[3], serverB1);
quickPickCheck(quickPick?.items[2], serverA1);

// Verify that we stick to our settings limit
for (let i = 0; i < Settings.JupyterServerUriListMax + 10; i = i + 1) {
addToUriList(mockStorage, i.toString(), i);
addToUriList(mockStorage, i.toString(), i, i.toString());
}

await ds.selectJupyterURI(true);
Expand Down