Add support for externally managed environment variables #201
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
Zephyr IDE was unconditionally overriding environment variables like
ZEPHYR_BASEandZEPHYR_SDK_INSTALL_DIR, breaking containerized workflows and pre-configured development environments. This caused issues for users working with:The extension was also setting
ZEPHYR_SDK_INSTALL_DIRunconditionally, even when no setup state existed, preventing users from maintaining their own environment configuration.Solution
This PR implements three complementary approaches to respect externally managed environments:
1. Configuration Setting
Users can now opt-in to using system environment variables by adding to
.vscode/settings.json:{ "zephyr-ide.use-system-environment": true }When enabled, Zephyr IDE will not override any environment variables (
ZEPHYR_BASE,ZEPHYR_SDK_INSTALL_DIR,VIRTUAL_ENV,PATH).2. Externally Managed Workspace
A new "Externally Managed" workspace type appears in the West Workspaces panel, allowing users to explicitly select externally managed mode via:
3. Fixed Environment Variable Management
Following maintainer guidance,
ZEPHYR_SDK_INSTALL_DIRis now only set when a setup state exists, preventing unconditional overrides.Changes
Core Logic (
src/utilities/utils.ts)reloadEnvironmentVariables()to checkuse-system-environmentsettingZEPHYR_SDK_INSTALL_DIRupdate insideif (setupState)checkSetup State (
src/setup_utilities/types.ts)externallyManaged?: booleanflag toSetupStateinterfacegenerateExternallyManagedSetupState()functionZEPHYR_BASEfrom system environment when in external modeUI Integration (
src/panels/west_workspace_view/WestWorkspaceView.ts)Command (
src/extension.ts,package.json)use-externally-managed-west-workspacecommanduse-system-environmentTesting and Documentation
src/test/externally-managed.test.ts)docs/externally-managed-environment.md)Use Cases
DevContainer Example
Docker Environment Example
Then enable
use-system-environmentsetting or select "Externally Managed" workspace.CI/CD Example
With
use-system-environment: truein settings, CI pipelines and local development both respect the environment.Backward Compatibility
✅ No breaking changes
use-system-environmentdefaults tofalse)Testing
Documentation
Comprehensive documentation added at
docs/externally-managed-environment.mdincluding:Fixes #86
Original prompt
Fixes #189
💡 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.