Skip to content

Commit 2693262

Browse files
authored
Remove polling to check shell integration (#1090)
Resolves: #1089 /cc @Tyriar
1 parent 8b4281e commit 2693262

File tree

4 files changed

+14
-35
lines changed

4 files changed

+14
-35
lines changed

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 & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
import { PythonCommandRunConfiguration, PythonEnvironment } from '../../../../api';
2-
import { traceInfo } from '../../../../common/logging';
3-
import { timeout } from '../../../../common/utils/asyncUtils';
42
import { isWindows } from '../../../../common/utils/platformUtils';
5-
import { activeTerminalShellIntegration } from '../../../../common/window.apis';
63
import { getConfiguration } from '../../../../common/workspace.apis';
74
import { ShellConstants } from '../../../common/shellConstants';
85
import { quoteArgs } from '../../../execution/execUtils';
9-
import { SHELL_INTEGRATION_POLL_INTERVAL, SHELL_INTEGRATION_TIMEOUT } from '../../utils';
106

117
function getCommandAsString(command: PythonCommandRunConfiguration[], shell: string, delimiter: string): string {
128
const parts = [];
@@ -101,26 +97,6 @@ export function extractProfilePath(content: string): string | undefined {
10197
return undefined;
10298
}
10399

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-
124100
export function isWsl(): boolean {
125101
// WSL sets these environment variables
126102
return !!(process.env.WSL_DISTRO_NAME || process.env.WSL_INTEROP || process.env.WSLENV);

src/features/terminal/terminalManager.ts

Lines changed: 7 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 {
@@ -154,17 +150,18 @@ export class TerminalManagerImpl implements TerminalManager {
154150
await Promise.all(
155151
providers.map(async (p) => {
156152
const state = await p.isSetup();
153+
// TODO: Consider removing setting check as it won't be as accurate to check
154+
// whether injection actually succeeded.
155+
// Perhaps use caching instead to avoid waiting.
157156
const shellIntegrationEnabledSetting = await getShellIntegrationEnabledCache();
158-
const shellIntegrationActiveTerminal = await shellIntegrationForActiveTerminal(p.name);
157+
const shellIntegrationActiveTerminal = await waitForShellIntegration(activeTerminal());
159158
const shellIntegrationLikelyAvailable =
160159
shellIntegrationEnabledSetting || shellIntegrationActiveTerminal;
161160
traceVerbose(`Checking shell profile for ${p.shellType}, with state: ${state}`);
162161

163162
if (state === ShellSetupState.NotSetup) {
164163
traceVerbose(
165-
`WSL detected: ${isWsl()}, Shell integration available from setting, or active terminal: ${shellIntegrationEnabledSetting}, or ${await shellIntegrationForActiveTerminal(
166-
p.name,
167-
)}`,
164+
`WSL detected: ${isWsl()}, Shell integration available from setting, or active terminal: ${shellIntegrationEnabledSetting}, or ${shellIntegrationActiveTerminal}`,
168165
);
169166

170167
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)