Skip to content

Commit 5ecd795

Browse files
authored
Handle activation disposes correctly (#128)
Fixes #127
1 parent 4c761a0 commit 5ecd795

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

src/features/terminal/terminalManager.ts

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,18 @@ export class TerminalManagerImpl implements TerminalManager {
157157
const execPromise = createDeferred<void>();
158158
const execution = shellIntegration.executeCommand(command.executable, command.args ?? []);
159159
const disposables: Disposable[] = [];
160+
let timer: NodeJS.Timeout | undefined = setTimeout(() => {
161+
execPromise.resolve();
162+
traceError(`Shell execution timed out: ${command.executable} ${command.args?.join(' ')}`);
163+
}, 2000);
160164
disposables.push(
161165
this.onTerminalShellExecutionEnd((e: TerminalShellExecutionEndEvent) => {
162166
if (e.execution === execution) {
163167
execPromise.resolve();
168+
if (timer) {
169+
clearTimeout(timer);
170+
timer = undefined;
171+
}
164172
}
165173
}),
166174
this.onTerminalShellExecutionStart((e: TerminalShellExecutionStartEvent) => {
@@ -170,8 +178,18 @@ export class TerminalManagerImpl implements TerminalManager {
170178
);
171179
}
172180
}),
181+
new Disposable(() => {
182+
if (timer) {
183+
clearTimeout(timer);
184+
timer = undefined;
185+
}
186+
}),
173187
);
174-
await execPromise.promise;
188+
try {
189+
await execPromise.promise;
190+
} finally {
191+
disposables.forEach((d) => d.dispose());
192+
}
175193
}
176194
} finally {
177195
this.activatedTerminals.set(terminal, environment);
@@ -191,10 +209,18 @@ export class TerminalManagerImpl implements TerminalManager {
191209
const execPromise = createDeferred<void>();
192210
const execution = shellIntegration.executeCommand(command.executable, command.args ?? []);
193211
const disposables: Disposable[] = [];
212+
let timer: NodeJS.Timeout | undefined = setTimeout(() => {
213+
execPromise.resolve();
214+
traceError(`Shell execution timed out: ${command.executable} ${command.args?.join(' ')}`);
215+
}, 2000);
194216
disposables.push(
195217
this.onTerminalShellExecutionEnd((e: TerminalShellExecutionEndEvent) => {
196218
if (e.execution === execution) {
197219
execPromise.resolve();
220+
if (timer) {
221+
clearTimeout(timer);
222+
timer = undefined;
223+
}
198224
}
199225
}),
200226
this.onTerminalShellExecutionStart((e: TerminalShellExecutionStartEvent) => {
@@ -204,6 +230,12 @@ export class TerminalManagerImpl implements TerminalManager {
204230
);
205231
}
206232
}),
233+
new Disposable(() => {
234+
if (timer) {
235+
clearTimeout(timer);
236+
timer = undefined;
237+
}
238+
}),
207239
);
208240

209241
await execPromise.promise;
@@ -348,7 +380,16 @@ export class TerminalManagerImpl implements TerminalManager {
348380
return env?.envId.id === environment?.envId.id;
349381
}
350382

383+
private isTaskTerminal(terminal: Terminal): boolean {
384+
// TODO: Need API for core for this https://github.com/microsoft/vscode/issues/234440
385+
return terminal.name.toLowerCase().includes('task');
386+
}
387+
351388
private async activateInternal(terminal: Terminal, environment: PythonEnvironment): Promise<void> {
389+
if (this.isTaskTerminal(terminal)) {
390+
return;
391+
}
392+
352393
if (terminal.shellIntegration) {
353394
await this.activateUsingShellIntegration(terminal.shellIntegration, terminal, environment);
354395
} else {
@@ -383,6 +424,10 @@ export class TerminalManagerImpl implements TerminalManager {
383424
}
384425

385426
private async deactivateInternal(terminal: Terminal, environment: PythonEnvironment): Promise<void> {
427+
if (this.isTaskTerminal(terminal)) {
428+
return;
429+
}
430+
386431
if (terminal.shellIntegration) {
387432
await this.deactivateUsingShellIntegration(terminal.shellIntegration, terminal, environment);
388433
} else {

0 commit comments

Comments
 (0)