Skip to content
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
15 changes: 10 additions & 5 deletions src/client/datascience/jupyter/kernels/kernelSelections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,18 @@ export class KernelSelectionProvider {
* @memberof KernelSelectionProvider
*/
public async getKernelSelectionsForRemoteSession(sessionManager: IJupyterSessionManager, cancelToken?: CancellationToken): Promise<IKernelSpecQuickPickItem[]> {
const liveItems = new ActiveJupyterSessionKernelSelectionListProvider(sessionManager, this.pathUtils).getKernelSelections(cancelToken).then(items => {
const getSelections = async () => {
const installedKernelsPromise = new InstalledJupyterKernelSelectionListProvider(this.kernelService, this.pathUtils, sessionManager).getKernelSelections(cancelToken);
const liveKernelsPromise = new ActiveJupyterSessionKernelSelectionListProvider(sessionManager, this.pathUtils).getKernelSelections(cancelToken);
const [installedKernels, liveKernels] = await Promise.all([installedKernelsPromise, liveKernelsPromise]);

// Sorty by name.
items.sort((a, b) => a.label === b.label ? 0 : (a.label > b.label ? 1 : -1));
this.remoteSuggestionsCache = items;
return items;
});
installedKernels.sort((a, b) => a.label === b.label ? 0 : (a.label > b.label ? 1 : -1));
liveKernels.sort((a, b) => a.label === b.label ? 0 : (a.label > b.label ? 1 : -1));
return [...liveKernels!, ...installedKernels!];
};

const liveItems = getSelections().then(items => this.localSuggestionsCache = items);
// If we have someting in cache, return that, while fetching in the background.
const cachedItems = this.remoteSuggestionsCache.length > 0 ? Promise.resolve(this.remoteSuggestionsCache) : liveItems;
return Promise.race([cachedItems, liveItems]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ suite('Data Science - KernelSelections', () => {
});

test('Should return an empty list for remote kernels if there are none', async () => {
when(kernelService.getKernelSpecs(instance(sessionManager), anything())).thenResolve([]);
when(sessionManager.getRunningKernels()).thenResolve([]);

const items = await kernelSelectionProvider.getKernelSelectionsForRemoteSession(instance(sessionManager));
Expand All @@ -83,6 +84,7 @@ suite('Data Science - KernelSelections', () => {
test('Should return a list with the proper details in the quick pick for remote connections (excluding non-python kernels)', async () => {
const activeKernels: IJupyterKernel[] = [activePython1KernelModel, activeJuliaKernelModel];

when(kernelService.getKernelSpecs(instance(sessionManager), anything())).thenResolve([]);
when(sessionManager.getRunningKernels()).thenResolve(activeKernels);
when(sessionManager.getKernelSpecs()).thenResolve(allSpecs);

Expand Down