-
Notifications
You must be signed in to change notification settings - Fork 37
Fix issue where terminal environment variables are not removed when they are commented out or deleted from .env files. #1131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -149,6 +149,8 @@ export class TerminalEnvVarInjector implements Disposable { | |
| traceVerbose( | ||
| `TerminalEnvVarInjector: Env file injection disabled for workspace: ${workspaceUri.fsPath}`, | ||
| ); | ||
| // Clear any previously set variables when injection is disabled | ||
| envVarScope.clear(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there is a potential issue here since when envVarScope.clear() is called on the scoped collection, it clears ALL variables in that workspace scope - not just the .env variables, but also the shell activation variables set by ShellStartupActivationVariablesManager. If you could review and confirm if this is the case or not that would be great! |
||
| return; | ||
| } | ||
|
|
||
|
|
@@ -165,14 +167,18 @@ export class TerminalEnvVarInjector implements Disposable { | |
| traceVerbose( | ||
| `TerminalEnvVarInjector: No .env file found for workspace: ${workspaceUri.fsPath}, not injecting environment variables.`, | ||
| ); | ||
| return; // No .env file to inject | ||
| // Clear any previously set variables when no .env file exists | ||
| envVarScope.clear(); | ||
| return; | ||
| } | ||
|
|
||
| // Clear all previously set variables before re-injecting. | ||
| // This ensures that when variables are commented out or removed from .env, | ||
| // they are properly removed from the terminal environment. | ||
| envVarScope.clear(); | ||
|
|
||
| for (const [key, value] of Object.entries(envVars)) { | ||
| if (value === undefined) { | ||
| // Remove the environment variable if the value is undefined | ||
| envVarScope.delete(key); | ||
| } else { | ||
| if (value !== undefined) { | ||
| envVarScope.replace(key, value); | ||
| } | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you test this with
python-envs.terminal.autoActivationTypeset to shell Startup?We don't want to clear variables from shell startup as that is what allows auto-activation for shell startup.
My concern is that calling clear on this will also clear activation related variable as well. These are variables with
VSCODE_PYTHON_(SHELL)_ACTIVATE