Skip to content

Commit f04c419

Browse files
authored
[Feature] add support for vscode env in dotenv (#1149)
* add support for vscode env with dotenv * fix typo
1 parent 9ab5f61 commit f04c419

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/utils/httpVariableProviders/systemVariableProvider.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as fs from 'fs-extra';
66
import * as path from 'path';
77
import { Clipboard, commands, env, QuickPickItem, QuickPickOptions, TextDocument, Uri, window } from 'vscode';
88
import * as Constants from '../../common/constants';
9+
import { EnvironmentController } from '../../controllers/environmentController';
910
import { HttpRequest } from '../../models/httpRequest';
1011
import { ResolveErrorMessage, ResolveWarningMessage } from '../../models/httpVariableResolveResult';
1112
import { VariableType } from '../../models/variableType';
@@ -188,13 +189,20 @@ export class SystemVariableProvider implements HttpVariableProvider {
188189
private registerDotenvVariable() {
189190
this.resolveFuncs.set(Constants.DotenvVariableName, async (name, document) => {
190191
let folderPath = path.dirname(document.fileName);
191-
while (!await fs.pathExists(path.join(folderPath, '.env'))) {
192+
const { name : environmentName } = await EnvironmentController.getCurrentEnvironment();
193+
194+
let pathsFound = [false, false];
195+
196+
while ((pathsFound = await Promise.all([
197+
fs.pathExists(path.join(folderPath, `.env.${environmentName}`)),
198+
fs.pathExists(path.join(folderPath, '.env'))
199+
])).every(result => result === false)) {
192200
folderPath = path.join(folderPath, '..');
193201
if (folderPath === path.parse(process.cwd()).root) {
194202
return { warning: ResolveWarningMessage.DotenvFileNotFound };
195203
}
196204
}
197-
const absolutePath = path.join(folderPath, '.env');
205+
const absolutePath = path.join(folderPath, pathsFound[0] ? `.env.${environmentName}` : '.env');
198206
const groups = this.dotenvRegex.exec(name);
199207
if (groups !== null && groups.length === 3) {
200208
const parsed = dotenv.parse(await fs.readFile(absolutePath));

0 commit comments

Comments
 (0)