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

Fix duplicate kernel generation #4790

Merged
merged 2 commits into from
Feb 12, 2021
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/4720.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixes problem with duplicate jupyter kernels being generated.
14 changes: 6 additions & 8 deletions src/client/datascience/kernel-launcher/kernelFinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,14 @@ export class KernelFinder implements IKernelFinder {
// Search all our local file system locations for installed kernel specs and return them
@captureTelemetry(Telemetry.KernelListingPerf)
public async listKernelSpecs(resource: Resource): Promise<IJupyterKernelSpec[]> {
if (!resource) {
// We need a resource to search for related kernel specs
return [];
}

// Get an id for the workspace folder, if we don't have one, use the fsPath of the resource
const workspaceFolderId = this.workspaceService.getWorkspaceFolderIdentifier(resource, resource.fsPath);
const workspaceFolderId = this.workspaceService.getWorkspaceFolderIdentifier(
resource,
resource?.fsPath || this.workspaceService.rootPath
);

// If we have not already searched for this resource, then generate the search
if (!this.workspaceToKernels.has(workspaceFolderId)) {
if (workspaceFolderId && !this.workspaceToKernels.has(workspaceFolderId)) {
this.workspaceToKernels.set(workspaceFolderId, this.findResourceKernelSpecs(resource));
}

Expand All @@ -119,7 +117,7 @@ export class KernelFinder implements IKernelFinder {
.then((items) =>
traceInfoIf(
!!process.env.VSC_JUPYTER_LOG_KERNEL_OUTPUT,
`Kernel specs for ${resource.toString()} are \n ${JSON.stringify(items)}`
`Kernel specs for ${resource?.toString() || 'undefined'} are \n ${JSON.stringify(items)}`
)
)
.catch(noop);
Expand Down
12 changes: 12 additions & 0 deletions src/test/datascience/dataScienceIocContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1272,6 +1272,9 @@ export class DataScienceIocContainer extends UnitTestIocContainer {
when(workspaceService.workspaceFolders).thenReturn(this.workspaceFolders);
when(workspaceService.rootPath).thenReturn(testWorkspaceFolder);
when(workspaceService.getWorkspaceFolder(anything())).thenCall(this.getWorkspaceFolder.bind(this));
when(workspaceService.getWorkspaceFolderIdentifier(anything(), anything())).thenCall(
this.getWorkspaceFolderIdentifier.bind(this)
);
this.addWorkspaceFolder(testWorkspaceFolder);
return workspaceService;
}
Expand All @@ -1282,6 +1285,15 @@ export class DataScienceIocContainer extends UnitTestIocContainer {
}
return undefined;
}
private getWorkspaceFolderIdentifier(uri: Resource, defaultValue: string | undefined): string | undefined {
if (uri) {
const folder = this.workspaceFolders.find((w) => w.ownedResources.has(uri.toString()));
if (folder) {
return folder.uri.fsPath;
}
}
return defaultValue;
}

private getResourceKey(resource: Resource): string {
if (!this.disposed) {
Expand Down