Skip to content

Commit 5236445

Browse files
committed
revert(terminal): replace pWaitFor with event-based shell integration wait
1 parent 44e7807 commit 5236445

2 files changed

Lines changed: 5 additions & 26 deletions

File tree

src/__mocks__/vscode.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ export const window = {
8181
sendText: () => {},
8282
}),
8383
onDidCloseTerminal: () => mockDisposable,
84-
onDidChangeTerminalShellIntegration: () => mockDisposable,
8584
createTextEditorDecorationType: () => ({ dispose: () => {} }),
8685
}
8786

src/integrations/terminal/Terminal.ts

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { existsSync } from "fs"
22
import * as path from "path"
33

44
import * as vscode from "vscode"
5+
import pWaitFor from "p-wait-for"
56

67
import type { RooTerminalCallbacks, RooTerminalProcessResultPromise } from "./types"
78
import { 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

Comments
 (0)