Skip to content

Commit 68de7c7

Browse files
committed
Remove polling to check shell integration
1 parent 8b4281e commit 68de7c7

4 files changed

Lines changed: 11 additions & 31 deletions

File tree

src/features/terminal/runInTerminal.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { ShellConstants } from '../common/shellConstants';
66
import { identifyTerminalShell } from '../common/shellDetector';
77
import { quoteArgs } from '../execution/execUtils';
88
import { normalizeShellPath } from './shells/common/shellUtils';
9+
import { traceLog } from '../../common/logging';
910

1011
export async function runInTerminal(
1112
environment: PythonEnvironment,
@@ -47,6 +48,7 @@ export async function runInTerminal(
4748
executable = `& ${executable}`;
4849
}
4950
execution = terminal.shellIntegration.executeCommand(executable, allArgs);
51+
traceLog(`runInTerminal: executeCommand ${executable} ${allArgs.join(' ')}`);
5052
await deferred.promise;
5153
} else {
5254
let text = quoteArgs([executable, ...allArgs]).join(' ');
@@ -55,5 +57,6 @@ export async function runInTerminal(
5557
text = `& ${text}`;
5658
}
5759
terminal.sendText(`${text}\n`);
60+
traceLog(`runInTerminal: sendText ${text}`);
5861
}
5962
}

src/features/terminal/shells/common/shellUtils.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -101,26 +101,6 @@ export function extractProfilePath(content: string): string | undefined {
101101
return undefined;
102102
}
103103

104-
export async function shellIntegrationForActiveTerminal(name: string, profile?: string): Promise<boolean> {
105-
let hasShellIntegration = activeTerminalShellIntegration();
106-
let timeOutstamp = 0;
107-
108-
while (!hasShellIntegration && timeOutstamp < SHELL_INTEGRATION_TIMEOUT) {
109-
await timeout(SHELL_INTEGRATION_POLL_INTERVAL);
110-
timeOutstamp += SHELL_INTEGRATION_POLL_INTERVAL;
111-
hasShellIntegration = activeTerminalShellIntegration();
112-
}
113-
114-
if (hasShellIntegration) {
115-
traceInfo(
116-
`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.`,
117-
);
118-
119-
return true;
120-
}
121-
return false;
122-
}
123-
124104
export function isWsl(): boolean {
125105
// WSL sets these environment variables
126106
return !!(process.env.WSL_DISTRO_NAME || process.env.WSL_INTEROP || process.env.WSLENV);

src/features/terminal/terminalManager.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { PythonEnvironment, PythonEnvironmentApi, PythonProject, PythonTerminalC
55
import { ActivationStrings } from '../../common/localize';
66
import { traceInfo, traceVerbose } from '../../common/logging';
77
import {
8+
activeTerminal,
89
createTerminal,
910
onDidChangeWindowState,
1011
onDidCloseTerminal,
@@ -16,12 +17,7 @@ import { getConfiguration, onDidChangeConfiguration } from '../../common/workspa
1617
import { isActivatableEnvironment } from '../common/activation';
1718
import { identifyTerminalShell } from '../common/shellDetector';
1819
import { getPythonApi } from '../pythonApi';
19-
import {
20-
getShellIntegrationEnabledCache,
21-
isWsl,
22-
shellIntegrationForActiveTerminal,
23-
shouldUseProfileActivation,
24-
} from './shells/common/shellUtils';
20+
import { getShellIntegrationEnabledCache, isWsl, shouldUseProfileActivation } from './shells/common/shellUtils';
2521
import { ShellEnvsProvider, ShellSetupState, ShellStartupScriptProvider } from './shells/startupProvider';
2622
import { handleSettingUpShellProfile } from './shellStartupSetupHandlers';
2723
import {
@@ -155,16 +151,14 @@ export class TerminalManagerImpl implements TerminalManager {
155151
providers.map(async (p) => {
156152
const state = await p.isSetup();
157153
const shellIntegrationEnabledSetting = await getShellIntegrationEnabledCache();
158-
const shellIntegrationActiveTerminal = await shellIntegrationForActiveTerminal(p.name);
154+
const shellIntegrationActiveTerminal = await waitForShellIntegration(activeTerminal());
159155
const shellIntegrationLikelyAvailable =
160156
shellIntegrationEnabledSetting || shellIntegrationActiveTerminal;
161157
traceVerbose(`Checking shell profile for ${p.shellType}, with state: ${state}`);
162158

163159
if (state === ShellSetupState.NotSetup) {
164160
traceVerbose(
165-
`WSL detected: ${isWsl()}, Shell integration available from setting, or active terminal: ${shellIntegrationEnabledSetting}, or ${await shellIntegrationForActiveTerminal(
166-
p.name,
167-
)}`,
161+
`WSL detected: ${isWsl()}, Shell integration available from setting, or active terminal: ${shellIntegrationEnabledSetting}, or ${shellIntegrationActiveTerminal}`,
168162
);
169163

170164
if (shellIntegrationLikelyAvailable && !shouldUseProfileActivation(p.shellType)) {

src/features/terminal/utils.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ export function getShellIntegrationTimeout(): number {
3030
* 2. Shell integration becoming available (window.onDidChangeTerminalShellIntegration event)
3131
* 3. Detection of common prompt patterns in terminal output
3232
*/
33-
export async function waitForShellIntegration(terminal: Terminal): Promise<boolean> {
33+
export async function waitForShellIntegration(terminal?: Terminal): Promise<boolean> {
34+
if (!terminal) {
35+
return false;
36+
}
3437
if (terminal.shellIntegration) {
3538
return true;
3639
}

0 commit comments

Comments
 (0)