@@ -143,6 +143,49 @@ export async function commonRunTestsHandler(controller: vscode.TestController, r
143143 console . log ( error ) ;
144144 }
145145
146+ // Map of uri strings checked for presence of a coverage.list file, recording the relative path of those that were found
147+ const mapCoverageLists = new Map < string , string > ( ) ;
148+ for await ( const mapInstance of mapTestClasses ) {
149+ const key = mapInstance [ 0 ] ;
150+ const pathParts = key . split ( '/' ) ;
151+ pathParts . pop ( ) ;
152+ const sourceBaseUri = mapInstance [ 1 ] . uri ?. with ( { path : mapInstance [ 1 ] . uri . path . split ( '/' ) . slice ( 0 , - pathParts . length ) . join ( '/' ) } ) ;
153+ if ( ! sourceBaseUri ) {
154+ console . log ( `No sourceBaseUri for key=${ key } ` ) ;
155+ continue ;
156+ }
157+ while ( pathParts . length > 1 ) {
158+ const currentPath = pathParts . join ( '/' ) ;
159+ // Check for coverage.list file here
160+ const coverageListUri = sourceBaseUri . with ( { path : sourceBaseUri . path . concat ( `${ currentPath } /coverage.list` ) } ) ;
161+ if ( mapCoverageLists . has ( coverageListUri . toString ( ) ) ) {
162+ // Already checked this uri path, and therefore all its ancestors
163+ break ;
164+ }
165+ try {
166+ await vscode . workspace . fs . stat ( coverageListUri ) ;
167+ mapCoverageLists . set ( coverageListUri . toString ( ) , currentPath ) ;
168+ } catch ( error ) {
169+ if ( error . code !== vscode . FileSystemError . FileNotFound ( ) . code ) {
170+ console . log ( `Error checking for ${ coverageListUri . toString ( ) } :` , error ) ;
171+ }
172+ mapCoverageLists . set ( coverageListUri . toString ( ) , '' ) ;
173+ }
174+ pathParts . pop ( ) ;
175+ }
176+ }
177+ // Copy all coverage.list files found into the corresponding place under testRoot
178+ for await ( const [ uriString , path ] of mapCoverageLists ) {
179+ if ( path . length > 0 ) {
180+ const coverageListUri = vscode . Uri . parse ( uriString , true ) ;
181+ try {
182+ await vscode . workspace . fs . copy ( coverageListUri , testRoot . with ( { path : testRoot . path . concat ( `${ path } /coverage.list` ) } ) ) ;
183+ } catch ( error ) {
184+ console . log ( `Error copying ${ coverageListUri . path } :` , error ) ;
185+ }
186+ }
187+ }
188+
146189 // Next, copy the classes into the folder as a package hierarchy
147190 for await ( const mapInstance of mapTestClasses ) {
148191 const key = mapInstance [ 0 ] ;
@@ -186,11 +229,12 @@ export async function commonRunTestsHandler(controller: vscode.TestController, r
186229 }
187230 }
188231
232+ const managerClass = request . profile ?. kind === vscode . TestRunProfileKind . Coverage ? "TestCoverage.Manager" : "%UnitTest.Manager" ;
189233 const configuration = {
190234 "type" : "objectscript" ,
191235 "request" : "launch" ,
192236 "name" : `${ controller . id . split ( "-" ) . pop ( ) } Tests:${ serverSpec . name } :${ namespace } :${ username } ` ,
193- "program" : `##class(%UnitTest.Manager ).RunTest("${ testSpec } ","${ runQualifiers } ")` ,
237+ "program" : `##class(${ managerClass } ).RunTest("${ testSpec } ","${ runQualifiers } ")` ,
194238
195239 // Extra properties needed by our DebugAdapterTracker
196240 "testingRunIndex" : runIndex ,
0 commit comments