Skip to content

Commit 8b4281e

Browse files
authored
createTerminal with command activation should return activated terminal (#1088)
Resolves: #1078
1 parent 2684465 commit 8b4281e

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

src/features/terminal/terminalActivationState.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { PythonEnvironment } from '../../api';
1111
import { traceError, traceInfo, traceVerbose } from '../../common/logging';
1212
import { onDidEndTerminalShellExecution, onDidStartTerminalShellExecution } from '../../common/window.apis';
1313
import { getActivationCommand, getDeactivationCommand } from '../common/activation';
14-
import { isTaskTerminal } from './utils';
14+
import { getShellIntegrationTimeout, isTaskTerminal } from './utils';
1515

1616
export interface DidChangeTerminalActivationStateEvent {
1717
terminal: Terminal;
@@ -252,12 +252,13 @@ export class TerminalActivationImpl implements TerminalActivationInternal {
252252
): Promise<boolean> {
253253
const execution = shellIntegration.executeCommand(command);
254254
const disposables: Disposable[] = [];
255+
const timeoutMs = getShellIntegrationTimeout();
255256

256257
const promise = new Promise<void>((resolve) => {
257258
const timer = setTimeout(() => {
258259
traceError(`Shell execution timed out: ${command}`);
259260
resolve();
260-
}, 2000);
261+
}, timeoutMs);
261262

262263
disposables.push(
263264
new Disposable(() => clearTimeout(timer)),

src/features/terminal/utils.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,21 @@ import { getConfiguration, getWorkspaceFolders } from '../../common/workspace.ap
99
export const SHELL_INTEGRATION_TIMEOUT = 500; // 0.5 seconds
1010
export const SHELL_INTEGRATION_POLL_INTERVAL = 20; // 0.02 seconds
1111

12+
/**
13+
* Use `terminal.integrated.shellIntegration.timeout` setting if available.
14+
* Falls back to defaults based on shell integration enabled state and remote environment.
15+
*/
16+
export function getShellIntegrationTimeout(): number {
17+
const config = getConfiguration('terminal.integrated');
18+
const timeoutValue = config.get<number | undefined>('shellIntegration.timeout');
19+
if (typeof timeoutValue !== 'number' || timeoutValue < 0) {
20+
const shellIntegrationEnabled = config.get<boolean>('shellIntegration.enabled', true);
21+
const isRemote = env.remoteName !== undefined;
22+
return shellIntegrationEnabled ? 5000 : isRemote ? 3000 : 2000;
23+
}
24+
return Math.max(timeoutValue, 500);
25+
}
26+
1227
/**
1328
* Three conditions in a Promise.race:
1429
* 1. Timeout based on VS Code's terminal.integrated.shellIntegration.timeout setting
@@ -20,16 +35,7 @@ export async function waitForShellIntegration(terminal: Terminal): Promise<boole
2035
return true;
2136
}
2237

23-
const config = getConfiguration('terminal.integrated');
24-
const shellIntegrationEnabled = config.get<boolean>('shellIntegration.enabled', true);
25-
const timeoutValue = config.get<number | undefined>('shellIntegration.timeout');
26-
const isRemote = env.remoteName !== undefined;
27-
let timeoutMs: number;
28-
if (typeof timeoutValue !== 'number' || timeoutValue < 0) {
29-
timeoutMs = shellIntegrationEnabled ? 5000 : isRemote ? 3000 : 2000;
30-
} else {
31-
timeoutMs = Math.max(timeoutValue, 500);
32-
}
38+
const timeoutMs = getShellIntegrationTimeout();
3339

3440
const disposables: Disposable[] = [];
3541

0 commit comments

Comments
 (0)