Skip to content

Add setting to enable environment variable injection with simplified configuration notifications#696

Closed
Copilot wants to merge 5 commits into
mainfrom
copilot/fix-695
Closed

Add setting to enable environment variable injection with simplified configuration notifications#696
Copilot wants to merge 5 commits into
mainfrom
copilot/fix-695

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Aug 7, 2025

This PR adds a new setting python.terminal.useEnvFile that controls whether environment variables from .env files and the python.envFile setting are injected into VS Code terminals, with a streamlined notification system to guide users when configuration is needed.

Changes

New Setting:

  • Name: python.terminal.useEnvFile
  • Type: boolean
  • Default: false (injection disabled by default)
  • Scope: resource (workspace-specific configuration)
  • Description: Controls whether environment variables from .env files and python.envFile setting are injected into terminals

Behavior

When false (default):

  • Environment variables from .env files are not injected into terminals
  • The TerminalEnvVarInjector logs that injection is disabled and skips processing
  • No environment variable processing occurs, improving performance when not needed

When true:

  • Environment variables are injected into terminals as before
  • All existing functionality is preserved
  • Supports both default .env files and custom python.envFile paths

Simplified Configuration Notifications:

  • Shows a notification only when a user sets python.envFile but python.terminal.useEnvFile remains false
  • The notification explains that the useEnvFile setting is required for python.envFile to take effect in terminals
  • Includes an "Open Settings" button for direct navigation to the python.terminal.useEnvFile setting
  • No notifications on extension startup - only when settings are actively changed

Implementation Details

The implementation uses a streamlined approach:

  1. Tracks only python.envFile setting changes to minimize complexity
  2. Shows notification only when python.envFile is updated and python.terminal.useEnvFile is false
  3. Uses positive injection logic (inject when enabled) for clearer code flow
  4. Includes proper localization support for setting descriptions

Performance Benefits:

  • Zero overhead when injection is disabled (default state)
  • Early exit from injection logic when useEnvFile is false
  • Efficient change detection with simplified state tracking

Developer Experience:

  • Clear, actionable notification that appears at the right time
  • Direct link to the relevant setting for quick resolution
  • Prevents the common scenario where users set python.envFile but don't realize useEnvFile needs to be enabled

Testing

  • Code compiles successfully with no breaking changes
  • Linting passes with no errors
  • The setting is properly configured in package.json with localization support

Fixes #695.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Aug 7, 2025

@eleanorjboyd 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.

I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.

…t variable injection

Co-authored-by: eleanorjboyd <26030610+eleanorjboyd@users.noreply.github.com>
Copilot AI changed the title [WIP] add setting to enable environment variable insertion Add setting to enable environment variable injection Aug 7, 2025
Copilot AI requested a review from eleanorjboyd August 7, 2025 19:26
@eleanorjboyd
Copy link
Copy Markdown
Member

@copilot switch the setting name to python.terminal.useEnvFile. Also if someone sets python.envFile but didnt change the value of useEnvFile pop up a notification that tells them such and that the useEnvFile setting is required for the python.envFile setting to take effect on the terminal. Thanks

…n for envFile usage

Co-authored-by: eleanorjboyd <26030610+eleanorjboyd@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Aug 7, 2025

@copilot switch the setting name to python.terminal.useEnvFile. Also if someone sets python.envFile but didnt change the value of useEnvFile pop up a notification that tells them such and that t...

Changed the setting name to python.terminal.useEnvFile and added notification logic. When python.envFile is configured but python.terminal.useEnvFile is false (default), users will see an informative message explaining that the useEnvFile setting is required for python.envFile to take effect in terminals, with an option to open Settings directly. Commit: 969135c

@eleanorjboyd
Copy link
Copy Markdown
Member

no i don't want "// Check if python.envFile is set but useEnvFile is false (default) and show notification" instead I want you to only show a notification IF that setting is updated. SO listen so a setting change and then show it otherwise it will be too noisy

Copy link
Copy Markdown
Member

@eleanorjboyd eleanorjboyd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot add an event to listen for a change in the useEnvFile or the python.envFile file value. If either is changed from unset -> set or from false -> true please show a notification to make sure the user has both settings enabled correctly for the expected behavior.

we might assume that a user would change python.envFile and not realize useEnvFile exists which would be frustrating if setting python.envFile doesn't work. this is an example scenario I am trying to avoid


// Show information message to user
showInformationMessage(
'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.',
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot do not show a notification here- I only want to notify the user if the change the value of the python.envFile NOT on extension start

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the immediate notification from the injection method. Notifications are now only shown when settings are actively changed via configuration change listeners, not on extension startup. Commit da4a6a8


if (!useEnvFile) {
traceVerbose(
`TerminalEnvVarInjector: Environment variable injection disabled for workspace: ${workspaceUri.fsPath}`,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switch this to only inject if useEnvFile is true- the turn to get out of injecting is a weird way to do this

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restructured the injection logic to use positive conditional injection - environment variables are now only injected when useEnvFile is true, instead of the early return pattern. This makes the logic clearer and more straightforward. Commit da4a6a8

Comment thread package.json Outdated
},
"python.terminal.useEnvFile": {
"type": "boolean",
"description": "Controls whether environment variables from .env files and python.envFile setting are injected into terminals",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use l10n for translations for descriptions and sentences

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added l10n support for the setting description. Updated package.json to use %python-envs.terminal.useEnvFile.description% and added the corresponding translation key to package.nls.json. Commit da4a6a8

…env settings

Co-authored-by: eleanorjboyd <26030610+eleanorjboyd@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Aug 11, 2025

no i don't want "// Check if python.envFile is set but useEnvFile is false (default) and show notification" instead I want you to only show a notification IF that setting is updated. SO listen so a se...

Implemented configuration change listeners instead of immediate notifications. The system now only shows notifications when settings are actively changed (unset->set or false->true) rather than on every extension start. Commit da4a6a8

@copilot add an event to listen for a change in the useEnvFile or the python.envFile file value. If either is changed from unset -> set or from false -> true please show a notification to make sure th...

Added event listeners for both python.terminal.useEnvFile and python.envFile settings. When either changes from unset->set or false->true, the system shows a notification to ensure both settings are configured correctly. This prevents the frustrating scenario where a user sets python.envFile but doesn't realize useEnvFile needs to be enabled. Commit da4a6a8

Copilot AI changed the title Add setting to enable environment variable injection Add setting to enable environment variable injection with smart configuration notifications Aug 11, 2025
Copilot AI requested a review from eleanorjboyd August 11, 2025 00:04
private async initialize(): Promise<void> {
traceVerbose('TerminalEnvVarInjector: Initializing environment variable injection');

// Initialize previous settings state for all workspaces
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot
no this is now too complicated. lets simplify it to just be:

if user updates python.envFile and they don't have python.useEnvFile set to true, show a notification.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplified the notification logic as requested. Now only shows a notification when user updates python.envFile and they don't have python.useEnvFile set to true. Removed the complex logic that tracked multiple settings and scenarios. Commit: 8ac5db2

…ut useEnvFile is false

Co-authored-by: eleanorjboyd <26030610+eleanorjboyd@users.noreply.github.com>
Copilot AI changed the title Add setting to enable environment variable injection with smart configuration notifications Add setting to enable environment variable injection with simplified configuration notifications Aug 11, 2025
Copilot AI requested a review from eleanorjboyd August 11, 2025 00:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add setting to enable environment variable insertion

2 participants