@@ -82,7 +82,10 @@ declare module "vscode" {
8282 // https://github.com/microsoft/vscode/blob/f0417069c62e20f3667506f4b7e53ca0004b4e3e/src/vscode-dts/vscode.d.ts#L10794
8383 interface Window {
8484 onDidStartTerminalShellExecution ?: (
85- listener : ( e : any ) => any ,
85+ listener : ( e : {
86+ terminal : vscode . Terminal
87+ execution : { read ( ) : AsyncIterable < string > ; commandLine : { value : string } }
88+ } ) => any ,
8689 thisArgs ?: any ,
8790 disposables ?: vscode . Disposable [ ] ,
8891 ) => vscode . Disposable
@@ -203,57 +206,77 @@ export class TerminalManager {
203206 constructor ( ) {
204207 let startDisposable : vscode . Disposable | undefined
205208 let endDisposable : vscode . Disposable | undefined
209+
206210 try {
207211 // onDidStartTerminalShellExecution
208212 startDisposable = ( vscode . window as vscode . Window ) . onDidStartTerminalShellExecution ?.( async ( e ) => {
209213 // Get a handle to the stream as early as possible:
210214 const stream = e ?. execution . read ( )
211215 const terminalInfo = TerminalRegistry . getTerminalInfoByTerminal ( e . terminal )
212- if ( stream && terminalInfo ) {
213- const process = this . processes . get ( terminalInfo . id )
214- if ( process ) {
215- terminalInfo . stream = stream
216- terminalInfo . running = true
217- terminalInfo . streamClosed = false
218- process . emit ( "stream_available" , terminalInfo . id , stream )
219- }
220- } else {
221- console . error ( "[TerminalManager] Stream failed, not registered for terminal" )
222- }
223216
224- console . info ( "[TerminalManager] Shell execution started: " , {
217+ console . info ( "[TerminalManager] shell execution started" , {
225218 hasExecution : ! ! e ?. execution ,
219+ hasStream : ! ! stream ,
226220 command : e ?. execution ?. commandLine ?. value ,
227221 terminalId : terminalInfo ?. id ,
228222 } )
223+
224+ if ( terminalInfo ) {
225+ const process = this . processes . get ( terminalInfo . id )
226+
227+ if ( process ) {
228+ if ( stream ) {
229+ terminalInfo . stream = stream
230+ terminalInfo . running = true
231+ terminalInfo . streamClosed = false
232+ console . log ( `[TerminalManager] stream_available -> ${ terminalInfo . id } ` )
233+ process . emit ( "stream_available" , terminalInfo . id , stream )
234+ } else {
235+ process . emit ( "stream_unavailable" , terminalInfo . id )
236+ console . error ( `[TerminalManager] stream_unavailable -> ${ terminalInfo . id } ` )
237+ }
238+ }
239+ } else {
240+ console . error ( "[TerminalManager] terminalInfo not available" )
241+ }
229242 } )
230243
231244 // onDidEndTerminalShellExecution
232245 endDisposable = ( vscode . window as vscode . Window ) . onDidEndTerminalShellExecution ?.( async ( e ) => {
233246 const exitDetails = this . interpretExitCode ( e ?. exitCode )
234- console . info ( "[TerminalManager] Shell execution ended:" , {
235- ...exitDetails ,
236- } )
247+ console . info ( "[TerminalManager] Shell execution ended:" , { ...exitDetails } )
248+ let emitted = false
237249
238- // Signal completion to any waiting processes
250+ // Signal completion to any waiting processes.
239251 for ( const id of this . terminalIds ) {
240252 const info = TerminalRegistry . getTerminal ( id )
253+
241254 if ( info && info . terminal === e . terminal ) {
242255 info . running = false
243256 const process = this . processes . get ( id )
257+
244258 if ( process ) {
259+ console . log ( `[TerminalManager] emitting shell_execution_complete -> ${ id } ` )
260+ emitted = true
245261 process . emit ( "shell_execution_complete" , id , exitDetails )
246262 }
263+
247264 break
248265 }
249266 }
267+
268+ if ( ! emitted ) {
269+ console . log ( `[TerminalManager#onDidStartTerminalShellExecution] no terminal found` )
270+ }
250271 } )
251272 } catch ( error ) {
252- console . error ( "[TerminalManager] Error setting up shell execution handlers: " , error )
273+ console . error ( "[TerminalManager] failed to configure shell execution handlers" , error )
253274 }
275+
254276 if ( startDisposable ) {
255277 this . disposables . push ( startDisposable )
256278 }
279+
257280 if ( endDisposable ) {
258281 this . disposables . push ( endDisposable )
259282 }
@@ -366,9 +389,6 @@ export class TerminalManager {
366389 }
367390
368391 disposeAll ( ) {
369- // for (const info of this.terminals) {
370- // //info.terminal.dispose() // dont want to dispose terminals when task is aborted
371- // }
372392 this . terminalIds . clear ( )
373393 this . processes . clear ( )
374394 this . disposables . forEach ( ( disposable ) => disposable . dispose ( ) )
0 commit comments