@@ -2,6 +2,7 @@ import { existsSync } from "fs"
22import * as path from "path"
33
44import * as vscode from "vscode"
5+ import pWaitFor from "p-wait-for"
56
67import type { RooTerminalCallbacks , RooTerminalProcessResultPromise } from "./types"
78import { BaseTerminal } from "./BaseTerminal"
@@ -102,30 +103,6 @@ export class Terminal extends BaseTerminal {
102103 reject ( error )
103104 } )
104105
105- // Wait for shell integration before executing the command. Use the
106- // event-based API rather than polling so we react immediately when
107- // VS Code's injector fires instead of burning CPU on a tight loop.
108- const waitForShellIntegration = ( ) : Promise < void > => {
109- if ( this . terminal . shellIntegration !== undefined ) {
110- return Promise . resolve ( )
111- }
112-
113- return new Promise < void > ( ( res , rej ) => {
114- const timeoutId = setTimeout ( ( ) => {
115- disposable . dispose ( )
116- rej ( new Error ( "timeout" ) )
117- } , Terminal . getShellIntegrationTimeout ( ) )
118-
119- const disposable = vscode . window . onDidChangeTerminalShellIntegration ( ( { terminal } ) => {
120- if ( terminal === this . terminal ) {
121- clearTimeout ( timeoutId )
122- disposable . dispose ( )
123- res ( )
124- }
125- } )
126- } )
127- }
128-
129106 if ( Terminal . isActiveShellCmdExe ( ) ) {
130107 // Keep this defensive fallback for callers that invoke Terminal.runCommand()
131108 // directly instead of routing through executeCommandInTerminal().
@@ -138,7 +115,10 @@ export class Terminal extends BaseTerminal {
138115 commandSubmitted : false ,
139116 } )
140117 } else {
141- waitForShellIntegration ( )
118+ // Wait for shell integration before executing the command
119+ pWaitFor ( ( ) => this . terminal . shellIntegration !== undefined , {
120+ timeout : Terminal . getShellIntegrationTimeout ( ) ,
121+ } )
142122 . then ( ( ) => {
143123 // Clean up temporary directory if shell integration is available, zsh did its job:
144124 ShellIntegrationManager . zshCleanupTmpDir ( this . id )
0 commit comments