@@ -98,17 +98,26 @@ export async function parseRequirementsFromFile(
9898}
9999
100100export function findEnvironmentInPath ( dirPath : string ) : string | null {
101+ // dirPath will be the path were the requirements are, but the env files are in the parent folder
102+ const parentDir = path . dirname ( dirPath ) ;
103+
104+ // the folder is named reqs-<envName>, so we cut out the correct env name to find the corresponding env file
105+ const baseFolder = path . basename ( dirPath ) ;
106+ const envName = baseFolder . split ( "reqs-" ) [ 1 ] ;
107+
101108 // Check if the directory contains an environment file
102- const files = fs . readdirSync ( dirPath ) ;
103- const envFiles = files . filter ( ( file : string ) => file . endsWith ( ".env" ) ) ;
109+ const files = fs . readdirSync ( parentDir ) ;
110+ const envFiles = files . filter ( ( file : string ) =>
111+ file . endsWith ( `${ envName } .env` )
112+ ) ;
104113
105114 // Now see if there is a directory with the same name as the env file
106115 for ( const file of envFiles ) {
107116 // remove ".env"
108117 const envName = file . slice ( 0 , - 4 ) ;
109- const envDirPath = path . join ( dirPath , envName ) ;
118+ const envDirPath = path . join ( parentDir , envName ) ;
110119 if ( fs . existsSync ( envDirPath ) && fs . lstatSync ( envDirPath ) . isDirectory ( ) ) {
111- return envName ;
120+ return envDirPath ;
112121 }
113122 }
114123 return null ;
@@ -125,18 +134,18 @@ export function setupRequirementsFileWatchers(
125134 if ( workspace . workspaceFolders && workspace . workspaceFolders . length > 0 ) {
126135 // Create a file watcher that watches for requirements files changes
127136 // using a glob pattern to match all reqs.csv and reqs.xlsx files in the workspace
128- requirementsFileWatcher =
129- workspace . createFileSystemWatcher ( "**/reqs.{csv,xlsx}" ) ;
137+ requirementsFileWatcher = workspace . createFileSystemWatcher (
138+ "**/reqs-*/reqs.{csv,xlsx}"
139+ ) ;
130140
131141 // When a requirements file is created
132142 requirementsFileWatcher . onDidCreate (
133143 async ( uri ) => {
134144 logCliOperation ( `Requirements file created: ${ uri . fsPath } ` ) ;
135145 const changeDir = path . dirname ( uri . fsPath ) ;
136- const envDirName = findEnvironmentInPath ( changeDir ) ;
137- if ( envDirName ) {
138- const envPath = path . join ( changeDir , envDirName ) ;
139- updateRequirementsAvailability ( envPath ) ;
146+ const envDirPath = findEnvironmentInPath ( changeDir ) ;
147+ if ( envDirPath ) {
148+ updateRequirementsAvailability ( envDirPath ) ;
140149 }
141150 } ,
142151 null ,
@@ -148,10 +157,9 @@ export function setupRequirementsFileWatchers(
148157 async ( uri ) => {
149158 logCliOperation ( `Requirements file deleted: ${ uri . fsPath } ` ) ;
150159 const parentDir = path . dirname ( uri . fsPath ) ;
151- const envDirName = findEnvironmentInPath ( parentDir ) ;
152- if ( envDirName ) {
153- const envPath = path . join ( parentDir , envDirName ) ;
154- updateRequirementsAvailability ( envPath ) ;
160+ const envDirPath = findEnvironmentInPath ( parentDir ) ;
161+ if ( envDirPath ) {
162+ updateRequirementsAvailability ( envDirPath ) ;
155163 }
156164 } ,
157165 null ,
0 commit comments