Skip to content

Commit 5ce1f78

Browse files
authored
Adapt to evaluating activate in core shell integration (#717)
Issue related: microsoft/vscode#259637 Adapting to: microsoft/vscode#261094 FYI if activation fails when eval from shell integration scripts, we're making it very obvious for them: microsoft/vscode#261094 (comment) TODO: Remove activation debris in shell init files for existing users. /cc @cwebster-99
1 parent 3f33fc2 commit 5ce1f78

File tree

11 files changed

+46
-8
lines changed

11 files changed

+46
-8
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"publisher": "ms-python",
77
"preview": true,
88
"engines": {
9-
"vscode": "^1.100.0-20250407"
9+
"vscode": "^1.104.0-20250815"
1010
},
1111
"categories": [
1212
"Other"

src/common/window.apis.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ export function activeTerminal(): Terminal | undefined {
6161
return window.activeTerminal;
6262
}
6363

64+
export function activeTerminalShellIntegration() {
65+
return window.activeTerminal?.shellIntegration;
66+
}
67+
6468
export function activeTextEditor(): TextEditor | undefined {
6569
return window.activeTextEditor;
6670
}

src/features/terminal/shellStartupSetupHandlers.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ export async function handleSettingUpShellProfile(
1111
callback: (provider: ShellStartupScriptProvider, result: boolean) => void,
1212
): Promise<void> {
1313
const shells = providers.map((p) => p.shellType).join(', ');
14+
// TODO: Get opinions on potentially modifying the prompt
15+
// - If shell integration is active, we won't need to modify user's shell profile, init scripts.
16+
// - Current prompt we have below may not be the most accurate description.
1417
const response = await showInformationMessage(
1518
l10n.t(
16-
'To enable "{0}" activation, your shell profile(s) need to be updated to include the necessary startup scripts. Would you like to proceed with these changes?',
19+
'To enable "{0}" activation, your shell profile(s) may need to be updated to include the necessary startup scripts. Would you like to proceed with these changes?',
1720
ACT_TYPE_SHELL,
1821
),
1922
{ modal: true, detail: l10n.t('Shells: {0}', shells) },
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export const BASH_ENV_KEY = 'VSCODE_BASH_ACTIVATE';
2-
export const ZSH_ENV_KEY = 'VSCODE_ZSH_ACTIVATE';
1+
export const BASH_ENV_KEY = 'VSCODE_PYTHON_BASH_ACTIVATE';
2+
export const ZSH_ENV_KEY = 'VSCODE_PYTHON_ZSH_ACTIVATE';
33
export const BASH_SCRIPT_VERSION = '0.1.1';

src/features/terminal/shells/bash/bashStartup.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import which from 'which';
55
import { traceError, traceInfo, traceVerbose } from '../../../../common/logging';
66
import { ShellConstants } from '../../../common/shellConstants';
77
import { hasStartupCode, insertStartupCode, removeStartupCode } from '../common/editUtils';
8+
import { shellIntegrationForActiveTerminal } from '../common/shellUtils';
89
import { ShellScriptEditState, ShellSetupState, ShellStartupScriptProvider } from '../startupProvider';
910
import { BASH_ENV_KEY, BASH_SCRIPT_VERSION, ZSH_ENV_KEY } from './bashConstants';
1011

@@ -69,6 +70,9 @@ async function isStartupSetup(profile: string, key: string): Promise<ShellSetupS
6970
}
7071

7172
async function setupStartup(profile: string, key: string, name: string): Promise<boolean> {
73+
if (shellIntegrationForActiveTerminal(name, profile)) {
74+
return true;
75+
}
7276
const activationContent = getActivationContent(key);
7377

7478
try {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export const CMD_ENV_KEY = 'VSCODE_CMD_ACTIVATE';
1+
export const CMD_ENV_KEY = 'VSCODE_PYTHON_CMD_ACTIVATE';
22
export const CMD_SCRIPT_VERSION = '0.1.0';

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { PythonCommandRunConfiguration, PythonEnvironment } from '../../../../api';
2+
import { traceInfo } from '../../../../common/logging';
23
import { isWindows } from '../../../../common/utils/platformUtils';
4+
import { activeTerminalShellIntegration } from '../../../../common/window.apis';
35
import { ShellConstants } from '../../../common/shellConstants';
46
import { quoteArgs } from '../../../execution/execUtils';
57

@@ -95,3 +97,16 @@ export function extractProfilePath(content: string): string | undefined {
9597
}
9698
return undefined;
9799
}
100+
101+
export function shellIntegrationForActiveTerminal(name: string, profile: string): boolean {
102+
const hasShellIntegration = activeTerminalShellIntegration();
103+
104+
if (hasShellIntegration) {
105+
traceInfo(
106+
`SHELL: Shell integration is available on your active terminal. Python activate scripts will be evaluated at shell integration level.
107+
Skipping modification of ${name} profile at: ${profile}`,
108+
);
109+
return true;
110+
}
111+
return false;
112+
}

src/features/terminal/shells/fish/fishStartup.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import which from 'which';
66
import { traceError, traceInfo, traceVerbose } from '../../../../common/logging';
77
import { ShellConstants } from '../../../common/shellConstants';
88
import { hasStartupCode, insertStartupCode, removeStartupCode } from '../common/editUtils';
9+
import { shellIntegrationForActiveTerminal } from '../common/shellUtils';
910
import { ShellScriptEditState, ShellSetupState, ShellStartupScriptProvider } from '../startupProvider';
1011
import { FISH_ENV_KEY, FISH_SCRIPT_VERSION } from './fishConstants';
1112

@@ -57,6 +58,9 @@ async function isStartupSetup(profilePath: string, key: string): Promise<boolean
5758

5859
async function setupStartup(profilePath: string, key: string): Promise<boolean> {
5960
try {
61+
if (shellIntegrationForActiveTerminal('fish', profilePath)) {
62+
return true;
63+
}
6064
const activationContent = getActivationContent(key);
6165
await fs.mkdirp(path.dirname(profilePath));
6266

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export const POWERSHELL_ENV_KEY = 'VSCODE_PWSH_ACTIVATE';
1+
export const POWERSHELL_ENV_KEY = 'VSCODE_PYTHON_PWSH_ACTIVATE';
22
export const PWSH_SCRIPT_VERSION = '0.1.1';

0 commit comments

Comments
 (0)