|
1 | 1 | // Copyright (c) Microsoft Corporation. All rights reserved. |
2 | 2 | // Licensed under the MIT License. |
3 | 3 |
|
4 | | -import * as fsapi from 'fs-extra'; |
| 4 | +import * as fse from 'fs-extra'; |
5 | 5 | import * as path from 'path'; |
6 | 6 | import { |
7 | 7 | Disposable, |
@@ -82,8 +82,7 @@ export class TerminalEnvVarInjector implements Disposable { |
82 | 82 | ); |
83 | 83 | await this.injectEnvironmentVariablesForWorkspace(workspaceFolder); |
84 | 84 | } else { |
85 | | - // Initial load - update all workspaces |
86 | | - traceVerbose('TerminalEnvVarInjector: Clearing existing environment variables for initial load'); |
| 85 | + // No provided workspace - update all workspaces |
87 | 86 | this.envVarCollection.clear(); |
88 | 87 |
|
89 | 88 | const workspaceFolders = workspace.workspaceFolders; |
@@ -115,29 +114,26 @@ export class TerminalEnvVarInjector implements Disposable { |
115 | 114 | // Track which .env file is being used for logging |
116 | 115 | const config = getConfiguration('python', workspaceUri); // why did this get .env file?? // returns like all of them |
117 | 116 | const envFilePath = config.get<string>('envFile'); |
118 | | - const resolvedEnvFilePath = envFilePath |
| 117 | + const resolvedEnvFilePath: string | undefined = envFilePath |
119 | 118 | ? path.resolve(resolveVariables(envFilePath, workspaceUri)) |
120 | 119 | : undefined; |
121 | | - const defaultEnvFilePath = path.join(workspaceUri.fsPath, '.env'); |
122 | | - |
123 | | - let activeEnvFilePath: string | undefined; |
124 | | - if (resolvedEnvFilePath && (await fsapi.pathExists(resolvedEnvFilePath))) { |
125 | | - activeEnvFilePath = resolvedEnvFilePath; |
126 | | - traceVerbose(`TerminalEnvVarInjector: Using python.envFile setting: ${activeEnvFilePath}`); |
127 | | - } else if (await fsapi.pathExists(defaultEnvFilePath)) { |
128 | | - activeEnvFilePath = defaultEnvFilePath; |
129 | | - traceVerbose(`TerminalEnvVarInjector: Using default .env file: ${activeEnvFilePath}`); |
| 120 | + const defaultEnvFilePath: string = path.join(workspaceUri.fsPath, '.env'); |
| 121 | + |
| 122 | + let activeEnvFilePath: string = resolvedEnvFilePath || defaultEnvFilePath; |
| 123 | + if (activeEnvFilePath && (await fse.pathExists(activeEnvFilePath))) { |
| 124 | + traceVerbose(`TerminalEnvVarInjector: Using env file: ${activeEnvFilePath}`); |
130 | 125 | } else { |
131 | | - traceVerbose(`TerminalEnvVarInjector: No .env file found for workspace: ${workspaceUri.fsPath}`); |
| 126 | + traceVerbose( |
| 127 | + `TerminalEnvVarInjector: No .env file found for workspace: ${workspaceUri.fsPath}, not injecting environment variables.`, |
| 128 | + ); |
132 | 129 | return; // No .env file to inject |
133 | 130 | } |
134 | 131 |
|
| 132 | + // use scoped environment variable collection |
135 | 133 | const envVarScope = this.getEnvironmentVariableCollectionScoped({ workspaceFolder }); |
136 | 134 | envVarScope.clear(); // Clear existing variables for this workspace |
137 | | - |
138 | | - // Inject environment variables into the collection |
| 135 | + |
139 | 136 | for (const [key, value] of Object.entries(envVars)) { |
140 | | - // inject into correctly scoped environment collection |
141 | 137 | if (value === undefined) { |
142 | 138 | // Remove the environment variable if the value is undefined |
143 | 139 | envVarScope.delete(key); |
|
0 commit comments