Skip to content

Commit f196dd1

Browse files
committed
Proper disposables
1 parent e6926b9 commit f196dd1

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

src/features/terminal/utils.ts

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as path from 'path';
2-
import { Terminal, TerminalOptions, Uri, window } from 'vscode';
2+
import { Disposable, Terminal, TerminalOptions, Uri, window } from 'vscode';
33
import { PythonEnvironment, PythonProject, PythonProjectEnvironmentApi, PythonProjectGetterApi } from '../../api';
4+
import { onDidChangeTerminalShellIntegration } from '../../common/window.apis';
45
import { getConfiguration, getWorkspaceFolders } from '../../common/workspace.apis';
56

67
export const SHELL_INTEGRATION_TIMEOUT = 500; // 0.5 seconds
@@ -21,25 +22,25 @@ export async function waitForShellIntegration(terminal: Terminal): Promise<boole
2122
const timeoutValue = config.get<number | undefined>('shellIntegration.timeout');
2223
const timeoutMs = timeoutValue === undefined || -1 ? 5000 : timeoutValue;
2324

24-
const disposables: { dispose(): void }[] = [];
25+
const disposables: Disposable[] = [];
2526

2627
try {
2728
const result = await Promise.race([
28-
// // Condition 1: Shell integration timeout setting
29-
// new Promise<boolean>((resolve) => {
30-
// setTimeout(() => resolve(false), timeoutMs);
31-
// }),
32-
33-
// // Condition 2: Shell integration becomes available
34-
// new Promise<boolean>((resolve) => {
35-
// disposables.push(
36-
// onDidChangeTerminalShellIntegration((e) => {
37-
// if (e.terminal === terminal) {
38-
// resolve(true);
39-
// }
40-
// }),
41-
// );
42-
// }),
29+
// Condition 1: Shell integration timeout setting
30+
new Promise<boolean>((resolve) => {
31+
setTimeout(() => resolve(false), timeoutMs);
32+
}),
33+
34+
// Condition 2: Shell integration becomes available
35+
new Promise<boolean>((resolve) => {
36+
disposables.push(
37+
onDidChangeTerminalShellIntegration((e) => {
38+
if (e.terminal === terminal) {
39+
resolve(true);
40+
}
41+
}),
42+
);
43+
}),
4344

4445
// Condition 3: Detect prompt patterns in terminal output
4546
new Promise<boolean>((resolve) => {
@@ -48,10 +49,8 @@ export async function waitForShellIntegration(terminal: Terminal): Promise<boole
4849
window.onDidWriteTerminalData((e) => {
4950
if (e.terminal === terminal) {
5051
dataSoFar += e.data;
51-
// TODO: Double check the regex.
5252
const lines = dataSoFar.split(/\r?\n/);
5353
const lastNonEmptyLine = lines.filter((line) => line.trim().length > 0).pop();
54-
5554
if (lastNonEmptyLine && detectsCommonPromptPattern(lastNonEmptyLine)) {
5655
resolve(false);
5756
}

0 commit comments

Comments
 (0)