From 68de7c7d986560438a40e846564adce2235e92a4 Mon Sep 17 00:00:00 2001 From: anthonykim1 Date: Fri, 9 Jan 2026 00:05:42 -0800 Subject: [PATCH 1/3] Remove polling to check shell integration --- src/features/terminal/runInTerminal.ts | 3 +++ .../terminal/shells/common/shellUtils.ts | 20 ------------------- src/features/terminal/terminalManager.ts | 14 ++++--------- src/features/terminal/utils.ts | 5 ++++- 4 files changed, 11 insertions(+), 31 deletions(-) diff --git a/src/features/terminal/runInTerminal.ts b/src/features/terminal/runInTerminal.ts index f0f4fcaf..b0cc9a59 100644 --- a/src/features/terminal/runInTerminal.ts +++ b/src/features/terminal/runInTerminal.ts @@ -6,6 +6,7 @@ import { ShellConstants } from '../common/shellConstants'; import { identifyTerminalShell } from '../common/shellDetector'; import { quoteArgs } from '../execution/execUtils'; import { normalizeShellPath } from './shells/common/shellUtils'; +import { traceLog } from '../../common/logging'; export async function runInTerminal( environment: PythonEnvironment, @@ -47,6 +48,7 @@ export async function runInTerminal( executable = `& ${executable}`; } execution = terminal.shellIntegration.executeCommand(executable, allArgs); + traceLog(`runInTerminal: executeCommand ${executable} ${allArgs.join(' ')}`); await deferred.promise; } else { let text = quoteArgs([executable, ...allArgs]).join(' '); @@ -55,5 +57,6 @@ export async function runInTerminal( text = `& ${text}`; } terminal.sendText(`${text}\n`); + traceLog(`runInTerminal: sendText ${text}`); } } diff --git a/src/features/terminal/shells/common/shellUtils.ts b/src/features/terminal/shells/common/shellUtils.ts index 192072f1..3a12aea4 100644 --- a/src/features/terminal/shells/common/shellUtils.ts +++ b/src/features/terminal/shells/common/shellUtils.ts @@ -101,26 +101,6 @@ export function extractProfilePath(content: string): string | undefined { return undefined; } -export async function shellIntegrationForActiveTerminal(name: string, profile?: string): Promise { - let hasShellIntegration = activeTerminalShellIntegration(); - let timeOutstamp = 0; - - while (!hasShellIntegration && timeOutstamp < SHELL_INTEGRATION_TIMEOUT) { - await timeout(SHELL_INTEGRATION_POLL_INTERVAL); - timeOutstamp += SHELL_INTEGRATION_POLL_INTERVAL; - hasShellIntegration = activeTerminalShellIntegration(); - } - - if (hasShellIntegration) { - traceInfo( - `SHELL: Shell integration is available on your active terminal, with name ${name} and profile ${profile}. Python activate scripts will be evaluated at shell integration level, except in WSL.`, - ); - - return true; - } - return false; -} - export function isWsl(): boolean { // WSL sets these environment variables return !!(process.env.WSL_DISTRO_NAME || process.env.WSL_INTEROP || process.env.WSLENV); diff --git a/src/features/terminal/terminalManager.ts b/src/features/terminal/terminalManager.ts index dcbce34b..c9e8d656 100644 --- a/src/features/terminal/terminalManager.ts +++ b/src/features/terminal/terminalManager.ts @@ -5,6 +5,7 @@ import { PythonEnvironment, PythonEnvironmentApi, PythonProject, PythonTerminalC import { ActivationStrings } from '../../common/localize'; import { traceInfo, traceVerbose } from '../../common/logging'; import { + activeTerminal, createTerminal, onDidChangeWindowState, onDidCloseTerminal, @@ -16,12 +17,7 @@ import { getConfiguration, onDidChangeConfiguration } from '../../common/workspa import { isActivatableEnvironment } from '../common/activation'; import { identifyTerminalShell } from '../common/shellDetector'; import { getPythonApi } from '../pythonApi'; -import { - getShellIntegrationEnabledCache, - isWsl, - shellIntegrationForActiveTerminal, - shouldUseProfileActivation, -} from './shells/common/shellUtils'; +import { getShellIntegrationEnabledCache, isWsl, shouldUseProfileActivation } from './shells/common/shellUtils'; import { ShellEnvsProvider, ShellSetupState, ShellStartupScriptProvider } from './shells/startupProvider'; import { handleSettingUpShellProfile } from './shellStartupSetupHandlers'; import { @@ -155,16 +151,14 @@ export class TerminalManagerImpl implements TerminalManager { providers.map(async (p) => { const state = await p.isSetup(); const shellIntegrationEnabledSetting = await getShellIntegrationEnabledCache(); - const shellIntegrationActiveTerminal = await shellIntegrationForActiveTerminal(p.name); + const shellIntegrationActiveTerminal = await waitForShellIntegration(activeTerminal()); const shellIntegrationLikelyAvailable = shellIntegrationEnabledSetting || shellIntegrationActiveTerminal; traceVerbose(`Checking shell profile for ${p.shellType}, with state: ${state}`); if (state === ShellSetupState.NotSetup) { traceVerbose( - `WSL detected: ${isWsl()}, Shell integration available from setting, or active terminal: ${shellIntegrationEnabledSetting}, or ${await shellIntegrationForActiveTerminal( - p.name, - )}`, + `WSL detected: ${isWsl()}, Shell integration available from setting, or active terminal: ${shellIntegrationEnabledSetting}, or ${shellIntegrationActiveTerminal}`, ); if (shellIntegrationLikelyAvailable && !shouldUseProfileActivation(p.shellType)) { diff --git a/src/features/terminal/utils.ts b/src/features/terminal/utils.ts index a7c75af0..a665d1d7 100644 --- a/src/features/terminal/utils.ts +++ b/src/features/terminal/utils.ts @@ -30,7 +30,10 @@ export function getShellIntegrationTimeout(): number { * 2. Shell integration becoming available (window.onDidChangeTerminalShellIntegration event) * 3. Detection of common prompt patterns in terminal output */ -export async function waitForShellIntegration(terminal: Terminal): Promise { +export async function waitForShellIntegration(terminal?: Terminal): Promise { + if (!terminal) { + return false; + } if (terminal.shellIntegration) { return true; } From b88c5a2021809833cf58e8829bd87c7320fdf816 Mon Sep 17 00:00:00 2001 From: anthonykim1 Date: Fri, 9 Jan 2026 00:13:15 -0800 Subject: [PATCH 2/3] add TODO --- src/features/terminal/terminalManager.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/features/terminal/terminalManager.ts b/src/features/terminal/terminalManager.ts index c9e8d656..425c851b 100644 --- a/src/features/terminal/terminalManager.ts +++ b/src/features/terminal/terminalManager.ts @@ -150,6 +150,9 @@ export class TerminalManagerImpl implements TerminalManager { await Promise.all( providers.map(async (p) => { const state = await p.isSetup(); + // TODO: Consider removing setting check as it won't be as accurate to check + // whether injection actually succeeded. + // Perhaps use caching instead to avoid waiting. const shellIntegrationEnabledSetting = await getShellIntegrationEnabledCache(); const shellIntegrationActiveTerminal = await waitForShellIntegration(activeTerminal()); const shellIntegrationLikelyAvailable = From a2b8729fc43a51ab2a595608d94b3b16b4c37000 Mon Sep 17 00:00:00 2001 From: anthonykim1 Date: Fri, 9 Jan 2026 00:15:40 -0800 Subject: [PATCH 3/3] Lint --- src/features/terminal/shells/common/shellUtils.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/features/terminal/shells/common/shellUtils.ts b/src/features/terminal/shells/common/shellUtils.ts index 3a12aea4..e662b337 100644 --- a/src/features/terminal/shells/common/shellUtils.ts +++ b/src/features/terminal/shells/common/shellUtils.ts @@ -1,12 +1,8 @@ import { PythonCommandRunConfiguration, PythonEnvironment } from '../../../../api'; -import { traceInfo } from '../../../../common/logging'; -import { timeout } from '../../../../common/utils/asyncUtils'; import { isWindows } from '../../../../common/utils/platformUtils'; -import { activeTerminalShellIntegration } from '../../../../common/window.apis'; import { getConfiguration } from '../../../../common/workspace.apis'; import { ShellConstants } from '../../../common/shellConstants'; import { quoteArgs } from '../../../execution/execUtils'; -import { SHELL_INTEGRATION_POLL_INTERVAL, SHELL_INTEGRATION_TIMEOUT } from '../../utils'; function getCommandAsString(command: PythonCommandRunConfiguration[], shell: string, delimiter: string): string { const parts = [];