Skip to content

Commit dc03549

Browse files
committed
fix: registered kernel is now recognized in ui
1 parent 635de8d commit dc03549

File tree

4 files changed

+17
-16
lines changed

4 files changed

+17
-16
lines changed

DEEPNOTE_KERNEL_IMPLEMENTATION.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ Create DeepnoteKernelConnectionMetadata
104104
105105
Register controller with IControllerRegistration
106106
107-
Execute notebook.selectKernel command
107+
Set controller affinity to Preferred (auto-selects kernel)
108108
109109
User runs cell → Executes on Deepnote kernel
110110
```

src/notebooks/controllers/controllerRegistration.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,14 +236,14 @@ export class ControllerRegistration implements IControllerRegistration, IExtensi
236236
}
237237
addOrUpdate(
238238
metadata: KernelConnectionMetadata,
239-
types: ('jupyter-notebook' | 'interactive')[]
239+
types: ('jupyter-notebook' | 'interactive' | 'deepnote')[]
240240
): IVSCodeNotebookController[] {
241241
const { added, existing } = this.addImpl(metadata, types, true);
242242
return added.concat(existing);
243243
}
244244
addImpl(
245245
metadata: KernelConnectionMetadata,
246-
types: ('jupyter-notebook' | 'interactive')[],
246+
types: ('jupyter-notebook' | 'interactive' | 'deepnote')[],
247247
triggerChangeEvent: boolean
248248
): { added: IVSCodeNotebookController[]; existing: IVSCodeNotebookController[] } {
249249
const added: IVSCodeNotebookController[] = [];
@@ -350,16 +350,19 @@ export class ControllerRegistration implements IControllerRegistration, IExtensi
350350
}
351351
get(
352352
metadata: KernelConnectionMetadata,
353-
notebookType: 'jupyter-notebook' | 'interactive'
353+
notebookType: 'jupyter-notebook' | 'interactive' | 'deepnote'
354354
): IVSCodeNotebookController | undefined {
355355
const id = this.getControllerId(metadata, notebookType);
356356
return this.registeredControllers.get(id);
357357
}
358358

359359
private getControllerId(
360360
metadata: KernelConnectionMetadata,
361-
viewType: typeof JupyterNotebookView | typeof InteractiveWindowView
361+
viewType: typeof JupyterNotebookView | typeof InteractiveWindowView | 'deepnote'
362362
) {
363+
if (viewType === 'deepnote') {
364+
return metadata.id;
365+
}
363366
return viewType === JupyterNotebookView ? metadata.id : `${metadata.id}${InteractiveControllerIdSuffix}`;
364367
}
365368

src/notebooks/controllers/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export interface IControllerRegistration {
8383
*/
8484
addOrUpdate(
8585
metadata: KernelConnectionMetadata,
86-
types: (typeof JupyterNotebookView | typeof InteractiveWindowView)[]
86+
types: (typeof JupyterNotebookView | typeof InteractiveWindowView | 'deepnote')[]
8787
): IVSCodeNotebookController[];
8888
/**
8989
* Gets the controller for a particular connection
@@ -92,7 +92,7 @@ export interface IControllerRegistration {
9292
*/
9393
get(
9494
connection: KernelConnectionMetadata,
95-
notebookType: typeof JupyterNotebookView | typeof InteractiveWindowView
95+
notebookType: typeof JupyterNotebookView | typeof InteractiveWindowView | 'deepnote'
9696
): IVSCodeNotebookController | undefined;
9797
}
9898

src/notebooks/deepnote/deepnoteKernelAutoSelector.node.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Licensed under the MIT License.
33

44
import { inject, injectable } from 'inversify';
5-
import { NotebookDocument, workspace, commands } from 'vscode';
5+
import { NotebookDocument, workspace, NotebookControllerAffinity } from 'vscode';
66
import { IExtensionSyncActivationService } from '../../platform/activation/types';
77
import { IDisposableRegistry } from '../../platform/common/types';
88
import { logger } from '../../platform/logging';
@@ -15,7 +15,7 @@ import {
1515
} from '../../kernels/deepnote/types';
1616
import { DeepnoteKernelConnectionMetadata } from '../../kernels/deepnote/types';
1717
import { IControllerRegistration } from '../controllers/types';
18-
import { JupyterNotebookView, JVSC_EXTENSION_ID } from '../../platform/common/constants';
18+
import { JVSC_EXTENSION_ID } from '../../platform/common/constants';
1919
import { getDisplayPath } from '../../platform/common/platform/fs-paths';
2020
import { createInterpreterKernelSpec } from '../../kernels/helpers';
2121
import { JupyterServerProviderHandle } from '../../kernels/jupyter/types';
@@ -116,8 +116,8 @@ export class DeepnoteKernelAutoSelector implements IDeepnoteKernelAutoSelector,
116116
serverProviderHandle
117117
});
118118

119-
// Register controller
120-
const controllers = this.controllerRegistration.addOrUpdate(connectionMetadata, [JupyterNotebookView]);
119+
// Register controller for deepnote notebook type
120+
const controllers = this.controllerRegistration.addOrUpdate(connectionMetadata, [DEEPNOTE_NOTEBOOK_TYPE]);
121121

122122
if (controllers.length === 0) {
123123
logger.error('Failed to create Deepnote kernel controller');
@@ -127,11 +127,9 @@ export class DeepnoteKernelAutoSelector implements IDeepnoteKernelAutoSelector,
127127
const controller = controllers[0];
128128
logger.info(`Created Deepnote kernel controller: ${controller.id}`);
129129

130-
// Auto-select the controller for this notebook
131-
await commands.executeCommand('notebook.selectKernel', {
132-
id: controller.id,
133-
extension: JVSC_EXTENSION_ID
134-
});
130+
// Auto-select the controller for this notebook using affinity
131+
// Setting NotebookControllerAffinity.Preferred will make VSCode automatically select this controller
132+
controller.controller.updateNotebookAffinity(notebook, NotebookControllerAffinity.Preferred);
135133

136134
logger.info(`Successfully auto-selected Deepnote kernel for ${getDisplayPath(notebook.uri)}`);
137135
} catch (ex) {

0 commit comments

Comments
 (0)