22// Licensed under the MIT License.
33
44import { inject , injectable } from 'inversify' ;
5- import { NotebookDocument , workspace , commands } from 'vscode' ;
5+ import { NotebookDocument , workspace , NotebookControllerAffinity } from 'vscode' ;
66import { IExtensionSyncActivationService } from '../../platform/activation/types' ;
77import { IDisposableRegistry } from '../../platform/common/types' ;
88import { logger } from '../../platform/logging' ;
@@ -15,7 +15,7 @@ import {
1515} from '../../kernels/deepnote/types' ;
1616import { DeepnoteKernelConnectionMetadata } from '../../kernels/deepnote/types' ;
1717import { IControllerRegistration } from '../controllers/types' ;
18- import { JupyterNotebookView , JVSC_EXTENSION_ID } from '../../platform/common/constants' ;
18+ import { JVSC_EXTENSION_ID } from '../../platform/common/constants' ;
1919import { getDisplayPath } from '../../platform/common/platform/fs-paths' ;
2020import { createInterpreterKernelSpec } from '../../kernels/helpers' ;
2121import { 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