@@ -62,11 +62,6 @@ const scriptEditorDebuggerExtension: JupyterFrontEndPlugin<void> = {
6262 }
6363
6464 const kernelSelection = ( widget as ScriptEditor ) . kernelSelection ;
65- const debuggerAvailable = await widget . debuggerAvailable ( kernelSelection ) ;
66-
67- if ( ! debuggerAvailable ) {
68- return ;
69- }
7065
7166 const sessions = app . serviceManager . sessions ;
7267 try {
@@ -80,7 +75,6 @@ const scriptEditorDebuggerExtension: JupyterFrontEndPlugin<void> = {
8075 activeSessions [ sessionModel . id ] = sessionConnection ;
8176 }
8277 }
83-
8478 if ( sessionModel ) {
8579 let sessionConnection : Session . ISessionConnection | null =
8680 activeSessions [ sessionModel . id ] ;
@@ -92,20 +86,14 @@ const scriptEditorDebuggerExtension: JupyterFrontEndPlugin<void> = {
9286 sessionConnection = sessions . connectTo ( { model : sessionModel } ) ;
9387 activeSessions [ sessionModel . id ] = sessionConnection ;
9488 }
95- if ( sessionModel . kernel ?. name !== kernelSelection ) {
96- // New kernel selection detected, update session connection
97- await changeKernel ( sessionConnection , kernelSelection ) ;
98- sessionModel = await sessions . findByPath ( path ) ;
99- if ( sessionConnection && sessionModel ) {
100- activeSessions [ sessionModel . id ] = sessionConnection ;
101- }
102- }
89+
90+ await updateKernel ( sessionConnection , kernelSelection ) ;
10391
10492 // Temporary solution to give enough time for the handler to update the UI on page reload.
10593 setTimeout ( async ( ) => {
10694 await handler . update ( widget , sessionConnection ) ;
10795 app . commands . notifyCommandChanged ( ) ;
108- } , 1000 ) ;
96+ } , 500 ) ;
10997 }
11098 } catch ( error ) {
11199 console . warn (
@@ -161,28 +149,29 @@ const scriptEditorDebuggerExtension: JupyterFrontEndPlugin<void> = {
161149 type : 'file' ,
162150 name : path
163151 } ;
164- let sessionConnection ;
152+ let sessionConnection = null ;
165153 try {
166- sessionConnection = await sessionManager . startNew ( options ) ;
167- sessionConnection . setPath ( path ) ;
168- console . log (
169- `Kernel session started for ${ path } with selected ${ kernelSelection } kernel.`
170- ) ;
154+ if ( kernelSelection ) {
155+ sessionConnection = await sessionManager . startNew ( options ) ;
156+ sessionConnection . setPath ( path ) ;
157+ console . log ( `Kernel session started for ${ kernelSelection } kernel` ) ;
158+ }
171159 } catch ( error ) {
172160 console . warn ( 'Exception: start session = ' + JSON . stringify ( error ) ) ;
173- sessionConnection = null ;
174161 }
175162 return sessionConnection ;
176163 } ;
177164
178- const changeKernel = async (
165+ const updateKernel = async (
179166 sessionConnection : Session . ISessionConnection ,
180167 kernelSelection : string
181168 ) : Promise < void > => {
182169 try {
183170 const prev = sessionConnection . kernel ?. name ;
184- await sessionConnection . changeKernel ( { name : kernelSelection } ) ;
185- console . log ( `Kernel change from ${ prev } to ${ kernelSelection } ` ) ;
171+ if ( kernelSelection && prev !== kernelSelection ) {
172+ await sessionConnection . changeKernel ( { name : kernelSelection } ) ;
173+ console . log ( `Kernel change from ${ prev } to ${ kernelSelection } ` ) ;
174+ }
186175 } catch ( error ) {
187176 console . warn ( 'Exception: change kernel = ' + JSON . stringify ( error ) ) ;
188177 }
0 commit comments