Skip to content

Commit 969135c

Browse files
Copiloteleanorjboyd
andcommitted
Change setting name to python.terminal.useEnvFile and add notification for envFile usage
Co-authored-by: eleanorjboyd <26030610+eleanorjboyd@users.noreply.github.com>
1 parent 46e9d38 commit 969135c

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
],
105105
"scope": "machine"
106106
},
107-
"python.terminal.injectEnvFile": {
107+
"python.terminal.useEnvFile": {
108108
"type": "boolean",
109109
"description": "Controls whether environment variables from .env files and python.envFile setting are injected into terminals",
110110
"default": false,

src/features/terminal/terminalEnvVarInjector.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
import { traceError, traceVerbose } from '../../common/logging';
1414
import { resolveVariables } from '../../common/utils/internalVariables';
1515
import { getConfiguration, getWorkspaceFolder } from '../../common/workspace.apis';
16+
import { showInformationMessage } from '../../common/window.apis';
1617
import { EnvVarManager } from '../execution/envVariableManager';
1718

1819
/**
@@ -111,13 +112,34 @@ export class TerminalEnvVarInjector implements Disposable {
111112
try {
112113
// Check if environment variable injection is enabled
113114
const config = getConfiguration('python', workspaceUri);
114-
const injectEnvFile = config.get<boolean>('terminal.injectEnvFile', false);
115+
const useEnvFile = config.get<boolean>('terminal.useEnvFile', false);
116+
const envFilePath = config.get<string>('envFile');
115117

116118
// use scoped environment variable collection
117119
const envVarScope = this.getEnvironmentVariableCollectionScoped({ workspaceFolder });
118120
envVarScope.clear(); // Clear existing variables for this workspace
119121

120-
if (!injectEnvFile) {
122+
// Check if python.envFile is set but useEnvFile is false (default) and show notification
123+
if (!useEnvFile && envFilePath) {
124+
traceVerbose(
125+
`TerminalEnvVarInjector: python.envFile is set but python.terminal.useEnvFile is false for workspace: ${workspaceUri.fsPath}`,
126+
);
127+
128+
// Show information message to user
129+
showInformationMessage(
130+
'The python.envFile setting is configured but will not take effect in terminals. Enable the "python.terminal.useEnvFile" setting to use environment variables from .env files in terminals.',
131+
'Open Settings'
132+
).then((selection) => {
133+
if (selection === 'Open Settings') {
134+
// Open VS Code settings to the python.terminal.useEnvFile setting
135+
import('vscode').then(vscode => {
136+
vscode.commands.executeCommand('workbench.action.openSettings', 'python.terminal.useEnvFile');
137+
});
138+
}
139+
});
140+
}
141+
142+
if (!useEnvFile) {
121143
traceVerbose(
122144
`TerminalEnvVarInjector: Environment variable injection disabled for workspace: ${workspaceUri.fsPath}`,
123145
);
@@ -127,7 +149,6 @@ export class TerminalEnvVarInjector implements Disposable {
127149
const envVars = await this.envVarManager.getEnvironmentVariables(workspaceUri);
128150

129151
// Track which .env file is being used for logging
130-
const envFilePath = config.get<string>('envFile');
131152
const resolvedEnvFilePath: string | undefined = envFilePath
132153
? path.resolve(resolveVariables(envFilePath, workspaceUri))
133154
: undefined;

0 commit comments

Comments
 (0)