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
3 changes: 3 additions & 0 deletions src/features/terminal/runInTerminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(' ');
Expand All @@ -55,5 +57,6 @@ export async function runInTerminal(
text = `& ${text}`;
}
terminal.sendText(`${text}\n`);
traceLog(`runInTerminal: sendText ${text}`);
}
}
24 changes: 0 additions & 24 deletions src/features/terminal/shells/common/shellUtils.ts
Original file line number Diff line number Diff line change
@@ -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 = [];
Expand Down Expand Up @@ -101,26 +97,6 @@ export function extractProfilePath(content: string): string | undefined {
return undefined;
}

export async function shellIntegrationForActiveTerminal(name: string, profile?: string): Promise<boolean> {
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);
Expand Down
17 changes: 7 additions & 10 deletions src/features/terminal/terminalManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand Down Expand Up @@ -154,17 +150,18 @@ 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 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)) {
Expand Down
5 changes: 4 additions & 1 deletion src/features/terminal/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean> {
export async function waitForShellIntegration(terminal?: Terminal): Promise<boolean> {
if (!terminal) {
return false;
}
if (terminal.shellIntegration) {
return true;
}
Expand Down
Loading