@@ -132,18 +132,13 @@ function createTests(response: TestsDiscoveryResponse, testController: TestContr
132132 groups . push ( groupId ) ;
133133 }
134134 } else {
135- // Single project - group at root level (skip DEFAULT_GROUP for cleaner view)
136- if ( group === 'DEFAULT_GROUP' ) {
137- // For single project with DEFAULT_GROUP, add tests at root level
138- groupItem = undefined ; // We'll add tests directly to the controller
139- } else {
140- const groupId = `group:${ group } ` ;
141- groupItem = testController . items . get ( groupId ) ;
142- if ( ! groupItem ) {
143- groupItem = testController . createTestItem ( groupId , group ) ;
144- testController . items . add ( groupItem ) ;
145- groups . push ( groupId ) ;
146- }
135+ // Single project - create group at root level (including DEFAULT_GROUP)
136+ const groupId = `group:${ group } ` ;
137+ groupItem = testController . items . get ( groupId ) ;
138+ if ( ! groupItem ) {
139+ groupItem = testController . createTestItem ( groupId , group ) ;
140+ testController . items . add ( groupItem ) ;
141+ groups . push ( groupId ) ;
147142 }
148143 }
149144
@@ -175,13 +170,7 @@ function createTests(response: TestsDiscoveryResponse, testController: TestContr
175170 ) ;
176171 testItem . range = new Range ( startPosition , endPosition ) ;
177172
178- // Add the test item to the appropriate parent
179- if ( groupItem ) {
180- groupItem . children . add ( testItem ) ;
181- } else {
182- // For single project with DEFAULT_GROUP, add directly to test controller
183- testController . items . add ( testItem ) ;
184- }
173+ groupItem . children . add ( testItem ) ;
185174 }
186175 }
187176}
@@ -192,9 +181,10 @@ export async function handleFileChange(ballerinaExtInstance: BallerinaExtension,
192181 // Determine which project this file belongs to
193182 const projectInfo = StateMachine . context ( ) . projectInfo ;
194183 let targetProjectPath : string | undefined ;
184+ const isWorkspace = projectInfo ?. children ?. length > 0 ;
195185
196186 // Check if this file belongs to a child project in a workspace
197- if ( projectInfo ?. children ?. length > 0 ) {
187+ if ( isWorkspace ) {
198188 for ( const child of projectInfo . children ) {
199189 if ( uri . path . startsWith ( child . projectPath ) ) {
200190 targetProjectPath = child . projectPath ;
@@ -221,9 +211,8 @@ export async function handleFileChange(ballerinaExtInstance: BallerinaExtension,
221211 return ;
222212 }
223213
224- handleFileDelete ( uri , testController ) ;
225- // Pass the project path to createTests for proper grouping
226- createTests ( response , testController , targetProjectPath ) ;
214+ await handleFileDelete ( uri , testController ) ;
215+ createTests ( response , testController , isWorkspace ? targetProjectPath : undefined ) ;
227216 setGroupsContext ( ) ;
228217}
229218
@@ -280,12 +269,7 @@ export async function handleFileDelete(uri: Uri, testController: TestController)
280269
281270 // Iterate over all root-level items in the Test Explorer
282271 testController . items . forEach ( ( item ) => {
283- if ( isTestFunctionItem ( item ) ) {
284- // If the item is a test function, check if it belongs to the deleted file
285- if ( belongsToFile ( item ) ) {
286- testController . items . delete ( item . id ) ;
287- }
288- } else if ( isProjectGroupItem ( item ) ) {
272+ if ( isProjectGroupItem ( item ) ) {
289273 // Only process this project group if it matches our target project
290274 const projectName = path . basename ( targetProjectPath ) ;
291275 if ( item . id !== `project:${ projectName } ` ) {
0 commit comments