Merge pull request #2 from RooVetGit/hotfix/vsCodeCompatabilityIssue

Fix vscode compatibility issue
This commit is contained in:
John Stearns
2024-11-01 15:56:18 -07:00
committed by GitHub

View File

@@ -70,15 +70,6 @@ Interestingly, some environments like Cursor enable these APIs even without the
This approach allows us to leverage advanced features when available while ensuring broad compatibility. This approach allows us to leverage advanced features when available while ensuring broad compatibility.
*/ */
declare module "vscode" { declare module "vscode" {
// https://github.com/microsoft/vscode/blob/f0417069c62e20f3667506f4b7e53ca0004b4e3e/src/vscode-dts/vscode.d.ts#L7442
interface Terminal {
shellIntegration?: {
cwd?: vscode.Uri
executeCommand?: (command: string) => {
read: () => AsyncIterable<string>
}
}
}
// https://github.com/microsoft/vscode/blob/f0417069c62e20f3667506f4b7e53ca0004b4e3e/src/vscode-dts/vscode.d.ts#L10794 // https://github.com/microsoft/vscode/blob/f0417069c62e20f3667506f4b7e53ca0004b4e3e/src/vscode-dts/vscode.d.ts#L10794
interface Window { interface Window {
onDidStartTerminalShellExecution?: ( onDidStartTerminalShellExecution?: (
@@ -89,6 +80,16 @@ declare module "vscode" {
} }
} }
// Extend the Terminal type to include our custom properties
type ExtendedTerminal = vscode.Terminal & {
shellIntegration?: {
cwd?: vscode.Uri
executeCommand?: (command: string) => {
read: () => AsyncIterable<string>
}
}
}
export class TerminalManager { export class TerminalManager {
private terminalIds: Set<number> = new Set() private terminalIds: Set<number> = new Set()
private processes: Map<number, TerminalProcess> = new Map() private processes: Map<number, TerminalProcess> = new Map()
@@ -139,16 +140,17 @@ export class TerminalManager {
}) })
// if shell integration is already active, run the command immediately // if shell integration is already active, run the command immediately
if (terminalInfo.terminal.shellIntegration) { const terminal = terminalInfo.terminal as ExtendedTerminal
if (terminal.shellIntegration) {
process.waitForShellIntegration = false process.waitForShellIntegration = false
process.run(terminalInfo.terminal, command) process.run(terminal, command)
} else { } else {
// docs recommend waiting 3s for shell integration to activate // docs recommend waiting 3s for shell integration to activate
pWaitFor(() => terminalInfo.terminal.shellIntegration !== undefined, { timeout: 4000 }).finally(() => { pWaitFor(() => (terminalInfo.terminal as ExtendedTerminal).shellIntegration !== undefined, { timeout: 4000 }).finally(() => {
const existingProcess = this.processes.get(terminalInfo.id) const existingProcess = this.processes.get(terminalInfo.id)
if (existingProcess && existingProcess.waitForShellIntegration) { if (existingProcess && existingProcess.waitForShellIntegration) {
existingProcess.waitForShellIntegration = false existingProcess.waitForShellIntegration = false
existingProcess.run(terminalInfo.terminal, command) existingProcess.run(terminal, command)
} }
}) })
} }
@@ -162,7 +164,8 @@ export class TerminalManager {
if (t.busy) { if (t.busy) {
return false return false
} }
const terminalCwd = t.terminal.shellIntegration?.cwd // one of cline's commands could have changed the cwd of the terminal const terminal = t.terminal as ExtendedTerminal
const terminalCwd = terminal.shellIntegration?.cwd // one of cline's commands could have changed the cwd of the terminal
if (!terminalCwd) { if (!terminalCwd) {
return false return false
} }