Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/features/terminal/terminalActivationState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -252,12 +252,13 @@ export class TerminalActivationImpl implements TerminalActivationInternal {
): Promise<boolean> {
const execution = shellIntegration.executeCommand(command);
const disposables: Disposable[] = [];
const timeoutMs = getShellIntegrationTimeout();

const promise = new Promise<void>((resolve) => {
const timer = setTimeout(() => {
traceError(`Shell execution timed out: ${command}`);
resolve();
}, 2000);
}, timeoutMs);

disposables.push(
new Disposable(() => clearTimeout(timer)),
Expand Down
26 changes: 16 additions & 10 deletions src/features/terminal/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<number | undefined>('shellIntegration.timeout');
if (typeof timeoutValue !== 'number' || timeoutValue < 0) {
const shellIntegrationEnabled = config.get<boolean>('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
Expand All @@ -20,16 +35,7 @@ export async function waitForShellIntegration(terminal: Terminal): Promise<boole
return true;
}

const config = getConfiguration('terminal.integrated');
const shellIntegrationEnabled = config.get<boolean>('shellIntegration.enabled', true);
const timeoutValue = config.get<number | undefined>('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[] = [];

Expand Down
Loading