-
Notifications
You must be signed in to change notification settings - Fork 30
Implement environment variable injection into VS Code terminals using GlobalEnvironmentVariableCollection #683
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
Conversation
…vironmentVariableCollection Co-authored-by: eleanorjboyd <[email protected]>
Co-authored-by: eleanorjboyd <[email protected]>
|
@copilot I have made a variety of changes and updates to the logic and code. Please update the tests to work with the new code and test this new logic |
…ogic Co-authored-by: eleanorjboyd <[email protected]>
I've updated the tests to work with the new code and test the new logic. The tests now properly validate:
Key changes made:
All 14 tests are now passing and cover the new functionality. Commit: 8daae4f |
|
@eleanorjboyd Since |
… GlobalEnvironmentVariableCollection (microsoft#683) This PR implements reactive environment variable injection into VS Code terminals using the `GlobalEnvironmentVariableCollection` API, enabling workspace-specific environment variables to be automatically available in all terminal sessions. ## Implementation Overview **New `TerminalEnvVarInjector` class** that: - Uses VS Code's `GlobalEnvironmentVariableCollection` to inject workspace environment variables into terminals - Integrates with the existing `PythonEnvVariableManager` to retrieve environment variables with proper precedence - Responds reactively to changes in `.env` files and `python.envFile` settings - Provides comprehensive logging at decision points using `traceVerbose` and `traceError` ## Key Features **Startup Behavior:** ```typescript // On extension startup, automatically loads and injects environment variables const envVars = await envVarManager.getEnvironmentVariables(workspaceUri); envVarCollection.clear(); for (const [key, value] of Object.entries(envVars)) { if (value !== process.env[key]) { envVarCollection.replace(key, value); } } ``` **Reactive Updates:** - **File changes**: Watches for changes to `.env` files through existing `onDidChangeEnvironmentVariables` event - **Setting changes**: Listens for changes to `python.envFile` configuration and switches to new files automatically - **Multi-workspace**: Handles multiple workspace folders by processing each separately **Smart Injection:** - Only injects variables that differ from `process.env` to avoid redundancy - Clears collection before re-injecting to ensure clean state - Gracefully handles missing files and configuration errors ## Integration Points - **Extension startup**: Integrated into `extension.ts` activation - **Existing infrastructure**: Uses `PythonEnvVariableManager.getEnvironmentVariables()` for consistent behavior - **Resource management**: Proper disposal and cleanup of watchers and subscriptions ## Testing Added comprehensive unit tests covering: - Environment variable injection on startup - Reactive updates to file and setting changes - Error handling for missing files and invalid configurations - Multi-workspace scenarios - Proper resource disposal This implementation follows VS Code extension best practices and provides the foundation for workspace-specific terminal environment configuration. Fixes microsoft#682. <!-- START COPILOT CODING AGENT TIPS --> --- 💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click [here](https://survey.alchemer.com/s3/8343779/Copilot-Coding-agent) to start the survey. --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: eleanorjboyd <[email protected]>
… GlobalEnvironmentVariableCollection (#683)
This PR implements reactive environment variable injection into VS Code
terminals using the `GlobalEnvironmentVariableCollection` API, enabling
workspace-specific environment variables to be automatically available
in all terminal sessions.
## Implementation Overview
**New `TerminalEnvVarInjector` class** that:
- Uses VS Code's `GlobalEnvironmentVariableCollection` to inject
workspace environment variables into terminals
- Integrates with the existing `PythonEnvVariableManager` to retrieve
environment variables with proper precedence
- Responds reactively to changes in `.env` files and `python.envFile`
settings
- Provides comprehensive logging at decision points using `traceVerbose`
and `traceError`
## Key Features
**Startup Behavior:**
```typescript
// On extension startup, automatically loads and injects environment variables
const envVars = await envVarManager.getEnvironmentVariables(workspaceUri);
envVarCollection.clear();
for (const [key, value] of Object.entries(envVars)) {
if (value !== process.env[key]) {
envVarCollection.replace(key, value);
}
}
```
**Reactive Updates:**
- **File changes**: Watches for changes to `.env` files through existing
`onDidChangeEnvironmentVariables` event
- **Setting changes**: Listens for changes to `python.envFile`
configuration and switches to new files automatically
- **Multi-workspace**: Handles multiple workspace folders by processing
each separately
**Smart Injection:**
- Only injects variables that differ from `process.env` to avoid
redundancy
- Clears collection before re-injecting to ensure clean state
- Gracefully handles missing files and configuration errors
## Integration Points
- **Extension startup**: Integrated into `extension.ts` activation
- **Existing infrastructure**: Uses
`PythonEnvVariableManager.getEnvironmentVariables()` for consistent
behavior
- **Resource management**: Proper disposal and cleanup of watchers and
subscriptions
## Testing
Added comprehensive unit tests covering:
- Environment variable injection on startup
- Reactive updates to file and setting changes
- Error handling for missing files and invalid configurations
- Multi-workspace scenarios
- Proper resource disposal
This implementation follows VS Code extension best practices and
provides the foundation for workspace-specific terminal environment
configuration.
Fixes #682.
<!-- START COPILOT CODING AGENT TIPS -->
---
💬 Share your feedback on Copilot coding agent for the chance to win a
$200 gift card! Click
[here](https://survey.alchemer.com/s3/8343779/Copilot-Coding-agent) to
start the survey.
---------
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: eleanorjboyd <[email protected]>
This PR implements reactive environment variable injection into VS Code terminals using the
GlobalEnvironmentVariableCollectionAPI, enabling workspace-specific environment variables to be automatically available in all terminal sessions.Implementation Overview
New
TerminalEnvVarInjectorclass that:GlobalEnvironmentVariableCollectionto inject workspace environment variables into terminalsPythonEnvVariableManagerto retrieve environment variables with proper precedence.envfiles andpython.envFilesettingstraceVerboseandtraceErrorKey Features
Startup Behavior:
Reactive Updates:
.envfiles through existingonDidChangeEnvironmentVariableseventpython.envFileconfiguration and switches to new files automaticallySmart Injection:
process.envto avoid redundancyIntegration Points
extension.tsactivationPythonEnvVariableManager.getEnvironmentVariables()for consistent behaviorTesting
Added comprehensive unit tests covering:
This implementation follows VS Code extension best practices and provides the foundation for workspace-specific terminal environment configuration.
Fixes #682.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.