diff --git a/src/features/terminal/terminalActivationState.ts b/src/features/terminal/terminalActivationState.ts index c0220883..5181c12f 100644 --- a/src/features/terminal/terminalActivationState.ts +++ b/src/features/terminal/terminalActivationState.ts @@ -11,7 +11,7 @@ import { PythonEnvironment } from '../../api'; import { traceError, traceInfo, traceVerbose } from '../../common/logging'; import { onDidEndTerminalShellExecution, onDidStartTerminalShellExecution } from '../../common/window.apis'; import { getActivationCommand, getDeactivationCommand } from '../common/activation'; -import { isTaskTerminal } from './utils'; +import { getShellIntegrationTimeout, isTaskTerminal } from './utils'; export interface DidChangeTerminalActivationStateEvent { terminal: Terminal; @@ -252,12 +252,13 @@ export class TerminalActivationImpl implements TerminalActivationInternal { ): Promise { const execution = shellIntegration.executeCommand(command); const disposables: Disposable[] = []; + const timeoutMs = getShellIntegrationTimeout(); const promise = new Promise((resolve) => { const timer = setTimeout(() => { traceError(`Shell execution timed out: ${command}`); resolve(); - }, 2000); + }, timeoutMs); disposables.push( new Disposable(() => clearTimeout(timer)), diff --git a/src/features/terminal/utils.ts b/src/features/terminal/utils.ts index bca60e08..a7c75af0 100644 --- a/src/features/terminal/utils.ts +++ b/src/features/terminal/utils.ts @@ -9,6 +9,21 @@ import { getConfiguration, getWorkspaceFolders } from '../../common/workspace.ap export const SHELL_INTEGRATION_TIMEOUT = 500; // 0.5 seconds export const SHELL_INTEGRATION_POLL_INTERVAL = 20; // 0.02 seconds +/** + * Use `terminal.integrated.shellIntegration.timeout` setting if available. + * Falls back to defaults based on shell integration enabled state and remote environment. + */ +export function getShellIntegrationTimeout(): number { + const config = getConfiguration('terminal.integrated'); + const timeoutValue = config.get('shellIntegration.timeout'); + if (typeof timeoutValue !== 'number' || timeoutValue < 0) { + const shellIntegrationEnabled = config.get('shellIntegration.enabled', true); + const isRemote = env.remoteName !== undefined; + return shellIntegrationEnabled ? 5000 : isRemote ? 3000 : 2000; + } + return Math.max(timeoutValue, 500); +} + /** * Three conditions in a Promise.race: * 1. Timeout based on VS Code's terminal.integrated.shellIntegration.timeout setting @@ -20,16 +35,7 @@ export async function waitForShellIntegration(terminal: Terminal): Promise('shellIntegration.enabled', true); - const timeoutValue = config.get('shellIntegration.timeout'); - const isRemote = env.remoteName !== undefined; - let timeoutMs: number; - if (typeof timeoutValue !== 'number' || timeoutValue < 0) { - timeoutMs = shellIntegrationEnabled ? 5000 : isRemote ? 3000 : 2000; - } else { - timeoutMs = Math.max(timeoutValue, 500); - } + const timeoutMs = getShellIntegrationTimeout(); const disposables: Disposable[] = [];