@@ -27,7 +27,7 @@ import { ContextKey } from '../../common/contextKey';
2727import { traceInfo , traceWarning } from '../../common/logger' ;
2828import { IFileSystem } from '../../common/platform/types' ;
2929import { IConfigurationService , IDisposableRegistry , ILogger } from '../../common/types' ;
30- import { createDeferred , Deferred , sleep } from '../../common/utils/async' ;
30+ import { createDeferred , Deferred } from '../../common/utils/async' ;
3131import * as localize from '../../common/utils/localize' ;
3232import { IInterpreterService , PythonInterpreter } from '../../interpreter/contracts' ;
3333import { captureTelemetry , sendTelemetryEvent } from '../../telemetry' ;
@@ -180,14 +180,9 @@ export class InteractiveWindow extends WebViewHost<IInteractiveWindowMapping> im
180180 return this . executeEvent . event ;
181181 }
182182
183- public addCode ( code : string , file : string , line : number , editor ?: TextEditor ) : Promise < void > {
183+ public addCode ( code : string , file : string , line : number , editor ?: TextEditor , debug ?: boolean ) : Promise < void > {
184184 // Call the internal method.
185- return this . submitCode ( code , file , line , undefined , editor ) ;
186- }
187-
188- public debugCode ( code : string , file : string , line : number , editor ?: TextEditor ) : Promise < void > {
189- // Call the internal method.
190- return this . debugCodeInternal ( code , file , line , undefined , editor ) ;
185+ return this . submitCode ( code , file , line , undefined , editor , debug ) ;
191186 }
192187
193188 // tslint:disable-next-line: no-any no-empty cyclomatic-complexity max-func-body-length
@@ -700,7 +695,7 @@ export class InteractiveWindow extends WebViewHost<IInteractiveWindowMapping> im
700695 }
701696 }
702697
703- private async submitCode ( code : string , file : string , line : number , id ?: string , _editor ?: TextEditor ) : Promise < void > {
698+ private async submitCode ( code : string , file : string , line : number , id ?: string , _editor ?: TextEditor , debug ?: boolean ) : Promise < void > {
704699 this . logger . logInformation ( `Submitting code for ${ this . id } ` ) ;
705700
706701 // Start a status item
@@ -749,6 +744,11 @@ export class InteractiveWindow extends WebViewHost<IInteractiveWindowMapping> im
749744 await this . jupyterServer . setInitialDirectory ( path . dirname ( file ) ) ;
750745 }
751746
747+ if ( debug ) {
748+ // Attach our debugger
749+ await this . debuggerAttach ( ) ;
750+ }
751+
752752 // Attempt to evaluate this cell in the jupyter notebook
753753 const observable = this . jupyterServer . executeObservable ( code , file , line , id , false ) ;
754754
@@ -774,6 +774,11 @@ export class InteractiveWindow extends WebViewHost<IInteractiveWindowMapping> im
774774 // Wait for the cell to finish
775775 await finishedAddingCode . promise ;
776776 traceInfo ( `Finished execution for ${ id } ` ) ;
777+
778+ // IANHU: Right spot here?
779+ if ( debug ) {
780+ this . debuggerDetach ( ) ;
781+ }
777782 }
778783 } catch ( err ) {
779784 status . dispose ( ) ;
@@ -788,12 +793,6 @@ export class InteractiveWindow extends WebViewHost<IInteractiveWindowMapping> im
788793 // Get our connection info
789794 const debugConnectInfo = await this . jupyterServer . getDebuggerInfo ( ) ;
790795
791- // tslint:disable-next-line:no-multiline-string
792- this . jupyterServer . execute ( `import ptvsd\r\nptvsd.wait_for_attach()` , Identifiers . EmptyFileName , 0 , uuid ( ) , undefined , true ) ;
793-
794- // IANHU: Not right. Just giving time to see if we have actually executed
795- await sleep ( 4000 ) ;
796-
797796 if ( debugConnectInfo ) {
798797 // First connect the VSCode UI
799798 const config : DebugConfiguration = {
@@ -807,6 +806,9 @@ export class InteractiveWindow extends WebViewHost<IInteractiveWindowMapping> im
807806 await this . debugService . startDebugging ( undefined , config ) ;
808807 }
809808
809+ // tslint:disable-next-line:no-multiline-string
810+ await this . jupyterServer . execute ( `import ptvsd\r\nptvsd.wait_for_attach()` , Identifiers . EmptyFileName , 0 , uuid ( ) , undefined , true ) ;
811+
810812 // Then enable tracing
811813 await this . jupyterServer . setDebugTracing ( true ) ;
812814 }
@@ -819,98 +821,8 @@ export class InteractiveWindow extends WebViewHost<IInteractiveWindowMapping> im
819821 }
820822
821823 // Stop our debugging UI session
822- //if (this.debugService.activeDebugSession) {
823- //this.debugService.activeDebugSession.
824- //}
825- }
826-
827- private async debugCodeInternal ( code : string , file : string , line : number , id ?: string , _editor ?: TextEditor ) : Promise < void > {
828- this . logger . logInformation ( `Submitting code for ${ this . id } ` ) ;
829-
830- // Start a status item
831- const status = this . setStatus ( localize . DataScience . executingCode ( ) ) ;
832-
833- // Transmit this submission to all other listeners (in a live share session)
834- if ( ! id ) {
835- id = uuid ( ) ;
836- this . shareMessage ( InteractiveWindowMessages . RemoteAddCode , { code, file, line, id, originator : this . id } ) ;
837- }
838-
839- // Create a deferred object that will wait until the status is disposed
840- const finishedAddingCode = createDeferred < void > ( ) ;
841- const actualDispose = status . dispose . bind ( status ) ;
842- status . dispose = ( ) => {
843- finishedAddingCode . resolve ( ) ;
844- actualDispose ( ) ;
845- } ;
846-
847- try {
848-
849- // Make sure we're loaded first.
850- try {
851- this . logger . logInformation ( 'Waiting for jupyter server and web panel ...' ) ;
852- await this . loadPromise ;
853- } catch ( exc ) {
854- // We should dispose ourselves if the load fails. Othewise the user
855- // updates their install and we just fail again because the load promise is the same.
856- this . dispose ( ) ;
857-
858- throw exc ;
859- }
860-
861- // Then show our webpanel
862- await this . show ( ) ;
863-
864- // Add our sys info if necessary
865- if ( file !== Identifiers . EmptyFileName ) {
866- await this . addSysInfo ( SysInfoReason . Start ) ;
867- }
868-
869- if ( this . jupyterServer ) {
870- // Before we try to execute code make sure that we have an initial directory set
871- // Normally set via the workspace, but we might not have one here if loading a single loose file
872- if ( file !== Identifiers . EmptyFileName ) {
873- await this . jupyterServer . setInitialDirectory ( path . dirname ( file ) ) ;
874- }
875-
876- // Attach our debugger
877- await this . debuggerAttach ( ) ;
878-
879- // Attempt to evaluate this cell in the jupyter notebook
880- const observable = this . jupyterServer . executeObservable ( code , file , line , id , false ) ;
881-
882- // Indicate we executed some code
883- this . executeEvent . fire ( code ) ;
884-
885- // Sign up for cell changes
886- observable . subscribe (
887- ( cells : ICell [ ] ) => {
888- this . onAddCodeEvent ( cells , undefined ) ;
889- } ,
890- ( error ) => {
891- status . dispose ( ) ;
892- if ( ! ( error instanceof CancellationError ) ) {
893- this . applicationShell . showErrorMessage ( error . toString ( ) ) ;
894- }
895- } ,
896- ( ) => {
897- // Indicate executing until this cell is done.
898- status . dispose ( ) ;
899- } ) ;
900-
901- // Wait for the cell to finish
902- await finishedAddingCode . promise ;
903- traceInfo ( `Finished execution for ${ id } ` ) ;
904-
905- // Detach our debugger
906- this . debuggerDetach ( ) ;
907- }
908- } catch ( err ) {
909- status . dispose ( ) ;
910-
911- const message = localize . DataScience . executingCodeFailure ( ) . format ( err ) ;
912- this . applicationShell . showErrorMessage ( message ) ;
913- }
824+ // IANHU: await not needed here?
825+ await this . commandManager . executeCommand ( 'workbench.action.debug.stop' ) ;
914826 }
915827
916828 private setStatus = ( message : string ) : Disposable => {
0 commit comments