@@ -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"
@@ -98,30 +99,6 @@ export class Terminal extends BaseTerminal {
9899 reject ( error )
99100 } )
100101
101- // Wait for shell integration before executing the command. Use the
102- // event-based API rather than polling so we react immediately when
103- // VS Code's injector fires instead of burning CPU on a tight loop.
104- const waitForShellIntegration = ( ) : Promise < void > => {
105- if ( this . terminal . shellIntegration !== undefined ) {
106- return Promise . resolve ( )
107- }
108-
109- return new Promise < void > ( ( res , rej ) => {
110- const timeoutId = setTimeout ( ( ) => {
111- disposable . dispose ( )
112- rej ( new Error ( "timeout" ) )
113- } , Terminal . getShellIntegrationTimeout ( ) )
114-
115- const disposable = vscode . window . onDidChangeTerminalShellIntegration ( ( { terminal } ) => {
116- if ( terminal === this . terminal ) {
117- clearTimeout ( timeoutId )
118- disposable . dispose ( )
119- res ( )
120- }
121- } )
122- } )
123- }
124-
125102 if ( Terminal . isActiveShellCmdExe ( ) ) {
126103 // cmd.exe cannot emit OSC 633;A — skip the timeout entirely and go
127104 // straight to the execa fallback (VS Code issue #164646).
@@ -132,7 +109,10 @@ export class Terminal extends BaseTerminal {
132109 commandSubmitted : false ,
133110 } )
134111 } else {
135- waitForShellIntegration ( )
112+ // Wait for shell integration before executing the command.
113+ pWaitFor ( ( ) => this . terminal . shellIntegration !== undefined , {
114+ timeout : Terminal . getShellIntegrationTimeout ( ) ,
115+ } )
136116 . then ( ( ) => {
137117 // Clean up temporary directory if shell integration is available, zsh did its job:
138118 ShellIntegrationManager . zshCleanupTmpDir ( this . id )
0 commit comments