Skip to content

Commit 8e00525

Browse files
authored
Fix: Getting an error on selecting an existing CI which has a display name from the historical CI's in the quick picks (#13642)
1 parent 63332cb commit 8e00525

File tree

7 files changed

+27
-15
lines changed

7 files changed

+27
-15
lines changed

news/2 Fixes/13387.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed connection to a Compute Instance from the quickpicks history options

src/client/datascience/common.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,23 @@ const AllowedKeys = {
4444
['execute_result']: new Set(Object.keys(dummyExecuteResultObj))
4545
};
4646

47-
export function getSavedUriList(globalState: Memento): { uri: string; time: number }[] {
48-
const uriList = globalState.get<{ uri: string; time: number }[]>(Settings.JupyterServerUriList);
47+
export function getSavedUriList(globalState: Memento): { uri: string; time: number; displayName?: string }[] {
48+
const uriList = globalState.get<{ uri: string; time: number; displayName?: string }[]>(
49+
Settings.JupyterServerUriList
50+
);
4951
return uriList
5052
? uriList.sort((a, b) => {
5153
return b.time - a.time;
5254
})
5355
: [];
5456
}
55-
export function addToUriList(globalState: Memento, uri: string, time: number) {
57+
export function addToUriList(globalState: Memento, uri: string, time: number, displayName: string) {
5658
const uriList = getSavedUriList(globalState);
5759

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

6365
globalState.update(Settings.JupyterServerUriList, editList).then(noop, noop);
6466
}

src/client/datascience/interactive-common/interactiveBase.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import { EXTENSION_ROOT_DIR, isTestExecution, PYTHON_LANGUAGE } from '../../comm
3737
import { RemoveKernelToolbarInInteractiveWindow, RunByLine } from '../../common/experiments/groups';
3838
import { traceError, traceInfo, traceWarning } from '../../common/logger';
3939

40+
import { isNil } from 'lodash';
4041
import {
4142
IConfigurationService,
4243
IDisposableRegistry,
@@ -1168,10 +1169,13 @@ export abstract class InteractiveBase extends WebViewHost<IInteractiveWindowMapp
11681169
if (serverConnection.localLaunch) {
11691170
localizedUri = localize.DataScience.localJupyterServer();
11701171
} else {
1171-
localizedUri = serverConnection.displayName;
1172-
11731172
// Log this remote URI into our MRU list
1174-
addToUriList(this.globalStorage, localizedUri, Date.now());
1173+
addToUriList(
1174+
this.globalStorage,
1175+
!isNil(serverConnection.url) ? serverConnection.url : serverConnection.displayName,
1176+
Date.now(),
1177+
serverConnection.displayName
1178+
);
11751179
}
11761180
}
11771181

src/client/datascience/jupyter/jupyterUtils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ export function createRemoteConnectionInfo(
7676
},
7777
dispose: noop,
7878
rootDirectory: '',
79-
getAuthHeader: serverUri ? () => getJupyterServerUri(uri)?.authorizationHeader : undefined
79+
getAuthHeader: serverUri ? () => getJupyterServerUri(uri)?.authorizationHeader : undefined,
80+
url: uri
8081
};
8182
}
8283

src/client/datascience/jupyter/serverSelector.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
'use strict';
55

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

3133
@injectable()
@@ -66,7 +68,7 @@ export class JupyterServerSelector {
6668
if (item.label === this.localLabel) {
6769
await this.setJupyterURIToLocal();
6870
} else if (!item.newChoice && !item.provider) {
69-
await this.setJupyterURIToRemote(item.label);
71+
await this.setJupyterURIToRemote(!isNil(item.url) ? item.url : item.label);
7072
} else if (!item.provider) {
7173
return this.selectRemoteURI.bind(this);
7274
} else {
@@ -208,9 +210,10 @@ export class JupyterServerSelector {
208210
if (uriItem.uri) {
209211
const uriDate = new Date(uriItem.time);
210212
items.push({
211-
label: uriItem.uri,
213+
label: !isNil(uriItem.displayName) ? uriItem.displayName : uriItem.uri,
212214
detail: DataScience.jupyterSelectURIMRUDetail().format(uriDate.toLocaleString()),
213-
newChoice: false
215+
newChoice: false,
216+
url: uriItem.uri
214217
});
215218
}
216219
});

src/client/datascience/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export interface IJupyterConnection extends Disposable {
7474
readonly hostName: string;
7575
localProcExitCode: number | undefined;
7676
readonly rootDirectory: string; // Directory where the notebook server was started.
77+
readonly url?: string;
7778
// tslint:disable-next-line: no-any
7879
getAuthHeader?(): any; // Snould be a json object
7980
}

src/test/datascience/jupyter/serverSelector.unit.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,31 +103,31 @@ suite('DataScience - Jupyter Server URI Selector', () => {
103103

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

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

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

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

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

133133
await ds.selectJupyterURI(true);

0 commit comments

Comments
 (0)