@@ -11,7 +11,7 @@ import * as timers from 'timers/promises';
1111import * as vscode from 'vscode' ;
1212import { ConfigValue } from './configValue' ;
1313import { ConsoleOuputChannel } from './consoleLogChannel' ;
14- import { getControllersForTestCommand } from './constants' ;
14+ import { getControllersForTestCommand , recreateControllersForTestCommand } from './constants' ;
1515import { initESBuild } from './esbuild' ;
1616import { TestRunner } from './runner' ;
1717import { SourceMapStore } from './source-map-store' ;
@@ -103,9 +103,7 @@ export function activate(context: vscode.ExtensionContext) {
103103 }
104104 } ;
105105
106- const initialSync = ( async ( ) => {
107- await initESBuild ( context , logChannel ) ;
108-
106+ async function syncWorkspaceFoldersWithRetry ( ) {
109107 // Workaround for vscode#179203 where findFiles doesn't work on startup.
110108 // This extension is only activated on workspaceContains, so we have pretty
111109 // high confidence that we should find something.
@@ -118,15 +116,31 @@ export function activate(context: vscode.ExtensionContext) {
118116
119117 await timers . setTimeout ( 1000 ) ;
120118 }
119+ }
120+
121+ const initialSync = ( async ( ) => {
122+ await initESBuild ( context , logChannel ) ;
123+ await syncWorkspaceFoldersWithRetry ( ) ;
121124 } ) ( ) ;
122125
123126 context . subscriptions . push (
124127 vscode . workspace . onDidChangeWorkspaceFolders ( syncWorkspaceFolders ) ,
125- vscode . commands . registerCommand ( getControllersForTestCommand , ( ) =>
126- initialSync . then ( ( ) =>
127- Array . from ( watchers . values ( ) ) . flatMap ( ( w ) => Array . from ( w . controllers . values ( ) ) ) ,
128- ) ,
129- ) ,
128+ vscode . commands . registerCommand ( getControllersForTestCommand , async ( ) => {
129+ await initialSync ;
130+ return Array . from ( watchers . values ( ) ) . flatMap ( ( w ) => Array . from ( w . controllers . values ( ) ) ) ;
131+ } ) ,
132+ vscode . commands . registerCommand ( recreateControllersForTestCommand , async ( ) => {
133+ logChannel . debug ( 'Destroying all watchers and test controllers' ) ;
134+ for ( const [ , watcher ] of watchers ) {
135+ watcher . dispose ( ) ;
136+ }
137+ watchers . clear ( ) ;
138+ resyncState = FolderSyncState . Idle ;
139+
140+ logChannel . debug ( 'Destroyed controllers, recreating' ) ;
141+ await syncWorkspaceFoldersWithRetry ( ) ;
142+ return Array . from ( watchers . values ( ) ) . flatMap ( ( w ) => Array . from ( w . controllers . values ( ) ) ) ;
143+ } ) ,
130144 new vscode . Disposable ( ( ) => watchers . forEach ( ( c ) => c . dispose ( ) ) ) ,
131145 logChannel ,
132146 ) ;
0 commit comments