Skip to content

Commit 1a1c2e7

Browse files
committed
use string for queue type []
1 parent 8fc330a commit 1a1c2e7

File tree

1 file changed

+18
-35
lines changed

1 file changed

+18
-35
lines changed

src/client/common/terminal/service.ts

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@ import { sleep } from '../utils/async';
2424
import { useEnvExtension } from '../../envExt/api.internal';
2525
import { ensureTerminalLegacy } from '../../envExt/api.legacy';
2626

27-
interface QueuedCommand {
28-
commandLine: string;
29-
resolve: (value: TerminalShellExecution | undefined) => void;
30-
}
31-
3227
@injectable()
3328
export class TerminalService implements ITerminalService, Disposable {
3429
private terminal?: Terminal;
@@ -41,7 +36,7 @@ export class TerminalService implements ITerminalService, Disposable {
4136
private applicationShell: IApplicationShell;
4237
private readonly executeCommandListeners: Set<Disposable> = new Set();
4338
private _terminalFirstLaunched: boolean = true;
44-
private pythonReplCommandQueue: QueuedCommand[] = [];
39+
private pythonReplCommandQueue: string[] = [];
4540
private isReplReady: boolean = false;
4641
private replDataListener?: Disposable;
4742
public get onDidCloseTerminal(): Event<void> {
@@ -94,19 +89,19 @@ export class TerminalService implements ITerminalService, Disposable {
9489
): Promise<TerminalShellExecution | undefined> {
9590
if (isPythonShell) {
9691
if (this.isReplReady) {
97-
return this.executeCommandInternal(commandLine, true);
98-
}
99-
100-
// Queue command and start listening for REPL prompt if not already
101-
return new Promise<TerminalShellExecution | undefined>((resolve) => {
102-
this.pythonReplCommandQueue.push({ commandLine, resolve });
103-
traceVerbose(`Queued Python REPL command: ${commandLine}`);
92+
this.terminal?.sendText(commandLine);
93+
traceVerbose(`Python REPL sendText: ${commandLine}`);
94+
} else {
95+
// Queue command to run once REPL is ready.
96+
this.pythonReplCommandQueue.push(commandLine);
97+
traceVerbose(`Python REPL queued command: ${commandLine}`);
10498
this.startReplListener();
105-
});
99+
}
100+
return undefined;
106101
}
107102

108103
// Non-REPL code execution
109-
return this.executeCommandInternal(commandLine, isPythonShell);
104+
return this.executeCommandInternal(commandLine);
110105
}
111106

112107
// Process Python code execution once REPL is detected.
@@ -138,21 +133,17 @@ export class TerminalService implements ITerminalService, Disposable {
138133
}
139134
}
140135

141-
private async flushReplQueue(): Promise<void> {
136+
private flushReplQueue(): void {
142137
while (this.pythonReplCommandQueue.length > 0) {
143-
const cmd = this.pythonReplCommandQueue.shift();
144-
if (cmd) {
145-
traceVerbose(`Executing queued REPL command: ${cmd.commandLine}`);
146-
const result = await this.executeCommandInternal(cmd.commandLine, true);
147-
cmd.resolve(result);
138+
const commandLine = this.pythonReplCommandQueue.shift();
139+
if (commandLine) {
140+
traceVerbose(`Executing queued REPL command: ${commandLine}`);
141+
this.terminal?.sendText(commandLine);
148142
}
149143
}
150144
}
151145

152-
private async executeCommandInternal(
153-
commandLine: string,
154-
isPythonShell: boolean,
155-
): Promise<TerminalShellExecution | undefined> {
146+
private async executeCommandInternal(commandLine: string): Promise<TerminalShellExecution | undefined> {
156147
const terminal = this.terminal;
157148
if (!terminal) {
158149
traceVerbose('Terminal not available, cannot execute command');
@@ -182,11 +173,7 @@ export class TerminalService implements ITerminalService, Disposable {
182173
await promise;
183174
}
184175

185-
if (isPythonShell) {
186-
// Prevent KeyboardInterrupt in Python REPL: https://github.com/microsoft/vscode-python/issues/25468
187-
terminal.sendText(commandLine);
188-
traceVerbose(`Python REPL detected, sendText: ${commandLine}`);
189-
} else if (terminal.shellIntegration) {
176+
if (terminal.shellIntegration) {
190177
const execution = terminal.shellIntegration.executeCommand(commandLine);
191178
traceVerbose(`Shell Integration is enabled, executeCommand: ${commandLine}`);
192179
return execution;
@@ -248,11 +235,7 @@ export class TerminalService implements ITerminalService, Disposable {
248235
// Reset REPL state when terminal closes
249236
this.isReplReady = false;
250237
this.disposeReplListener();
251-
// Clear any pending commands
252-
while (this.pythonReplCommandQueue.length > 0) {
253-
const cmd = this.pythonReplCommandQueue.shift();
254-
cmd?.resolve(undefined);
255-
}
238+
this.pythonReplCommandQueue = [];
256239
}
257240
}
258241

0 commit comments

Comments
 (0)