@@ -37,55 +37,56 @@ export async function registerNoConfigDebug(context: IExtensionContext): Promise
3737 collection . replace ( 'BUNDLED_DEBUGPY_PATH' , bundledDebugPath ) ;
3838
3939 // create file system watcher for the debuggerAdapterEndpointFolder for when the communication port is written
40- context . subscriptions . push (
41- createFileSystemWatcher ( new RelativePattern ( debugAdapterEndpointDir , '**/*' ) ) . onDidCreate ( ( uri ) => {
42- const filePath = uri . fsPath ;
43- fs . readFile ( filePath , ( err , data ) => {
44- const dataParse = data . toString ( ) ;
45- if ( err ) {
46- traceError ( `Error reading debuggerAdapterEndpoint.txt file: ${ err } ` ) ;
47- return ;
48- }
49- try {
50- // parse the client port
51- const jsonData = JSON . parse ( dataParse ) ;
52- const clientPort = jsonData . client ?. port ;
53- traceVerbose ( `Parsed client port: ${ clientPort } ` ) ;
40+ const fileSystemWatcher = createFileSystemWatcher ( new RelativePattern ( debugAdapterEndpointDir , '**/*' ) ) ;
41+ const fileCreationEvent = fileSystemWatcher . onDidCreate ( async ( uri ) => {
42+ const filePath = uri . fsPath ;
43+ fs . readFile ( filePath , ( err , data ) => {
44+ const dataParse = data . toString ( ) ;
45+ if ( err ) {
46+ traceError ( `Error reading debuggerAdapterEndpoint.txt file: ${ err } ` ) ;
47+ return ;
48+ }
49+ try {
50+ // parse the client port
51+ const jsonData = JSON . parse ( dataParse ) ;
52+ const clientPort = jsonData . client ?. port ;
53+ traceVerbose ( `Parsed client port: ${ clientPort } ` ) ;
5454
55- const options : DebugSessionOptions = {
56- noDebug : false ,
57- } ;
55+ const options : DebugSessionOptions = {
56+ noDebug : false ,
57+ } ;
5858
59- // start debug session with the client port
60- debugStartDebugging (
61- undefined ,
62- {
63- type : 'python' ,
64- request : 'attach' ,
65- name : 'Attach to Python' ,
66- connect : {
67- port : clientPort ,
68- host : 'localhost' ,
69- } ,
59+ // start debug session with the client port
60+ debugStartDebugging (
61+ undefined ,
62+ {
63+ type : 'python' ,
64+ request : 'attach' ,
65+ name : 'Attach to Python' ,
66+ connect : {
67+ port : clientPort ,
68+ host : 'localhost' ,
7069 } ,
71- options ,
72- ) . then (
73- ( started ) => {
74- if ( started ) {
75- traceVerbose ( 'Successfully started debug session' ) ;
76- } else {
77- traceError ( 'Error starting debug session, session not started.' ) ;
78- }
79- } ,
80- ( error ) => {
81- traceError ( `Error starting debug session: ${ error } ` ) ;
82- } ,
83- ) ;
84- } catch ( parseErr ) {
85- traceError ( `Error parsing JSON: ${ parseErr } ` ) ;
86- }
87- } ) ;
88- JSON . parse ;
89- } ) ,
90- ) ;
70+ } ,
71+ options ,
72+ ) . then (
73+ ( started ) => {
74+ if ( started ) {
75+ traceVerbose ( 'Successfully started debug session' ) ;
76+ } else {
77+ traceError ( 'Error starting debug session, session not started.' ) ;
78+ }
79+ } ,
80+ ( error ) => {
81+ traceError ( `Error starting debug session: ${ error } ` ) ;
82+ } ,
83+ ) ;
84+ } catch ( parseErr ) {
85+ traceError ( `Error parsing JSON: ${ parseErr } ` ) ;
86+ }
87+ } ) ;
88+ JSON . parse ;
89+ } ) ;
90+ context . subscriptions . push ( fileCreationEvent ) ;
91+ context . subscriptions . push ( fileSystemWatcher ) ;
9192}
0 commit comments