@@ -6,6 +6,7 @@ import * as fs from 'fs-extra';
66import * as path from 'path' ;
77import { Clipboard , commands , env , QuickPickItem , QuickPickOptions , TextDocument , Uri , window } from 'vscode' ;
88import * as Constants from '../../common/constants' ;
9+ import { EnvironmentController } from '../../controllers/environmentController' ;
910import { HttpRequest } from '../../models/httpRequest' ;
1011import { ResolveErrorMessage , ResolveWarningMessage } from '../../models/httpVariableResolveResult' ;
1112import { 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