@@ -163,6 +163,8 @@ export function getXmlUri(uri: vscode.Uri): vscode.Uri {
163163}
164164let reporter : TelemetryReporter = null ;
165165
166+ export let checkingConnection = false ;
167+
166168let serverManagerApi : any ;
167169
168170// Map of the intersystems.server connection specs we have resolved via the API to that extension
@@ -191,6 +193,11 @@ export function getResolvedConnectionSpec(key: string, dflt: any): any {
191193}
192194
193195export async function checkConnection ( clearCookies = false , uri ?: vscode . Uri ) : Promise < void > {
196+ // Do nothing if already checking the connection
197+ if ( checkingConnection ) {
198+ return ;
199+ }
200+
194201 const { apiTarget, configName } = connectionTarget ( uri ) ;
195202 if ( clearCookies ) {
196203 /// clean-up cached values
@@ -268,7 +275,8 @@ export async function checkConnection(clearCookies = false, uri?: vscode.Uri): P
268275 disableConnection ( configName ) ;
269276 return ;
270277 }
271- api
278+ checkingConnection = true ;
279+ return api
272280 . serverInfo ( )
273281 . then ( ( info ) => {
274282 panel . text = api . connInfo ;
@@ -279,6 +287,7 @@ export async function checkConnection(clearCookies = false, uri?: vscode.Uri): P
279287 serverVersion : info . result . content . version ,
280288 healthshare : hasHS ? "yes" : "no" ,
281289 } ) ;
290+ return ;
282291 } )
283292 . catch ( ( error ) => {
284293 let message = error . message ;
@@ -324,10 +333,13 @@ export async function checkConnection(clearCookies = false, uri?: vscode.Uri): P
324333 throw error ;
325334 } )
326335 . finally ( ( ) => {
327- explorerProvider . refresh ( ) ;
328- if ( uri && schemas . includes ( uri . scheme ) ) {
329- vscode . commands . executeCommand ( "workbench.files.action.refreshFilesExplorer" ) ;
330- }
336+ checkingConnection = false ;
337+ setTimeout ( ( ) => {
338+ explorerProvider . refresh ( ) ;
339+ if ( uri && schemas . includes ( uri . scheme ) ) {
340+ vscode . commands . executeCommand ( "workbench.files.action.refreshFilesExplorer" ) ;
341+ }
342+ } , 20 ) ;
331343 } ) ;
332344}
333345
@@ -487,7 +499,8 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
487499 const uri = oneToCheck [ 1 ] ;
488500 const serverName = uri . scheme === "file" ? config ( "conn" , configName ) . server : configName ;
489501 await resolveConnectionSpec ( serverName ) ;
490- await checkConnection ( true , uri ) ;
502+ // Ignore any failure
503+ checkConnection ( true , uri ) . finally ( ) ;
491504 }
492505
493506 vscode . workspace . onDidChangeWorkspaceFolders ( async ( { added, removed } ) => {
@@ -522,8 +535,34 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
522535
523536 vscode . workspace . onDidChangeConfiguration ( async ( { affectsConfiguration } ) => {
524537 if ( affectsConfiguration ( "objectscript.conn" ) || affectsConfiguration ( "intersystems.servers" ) ) {
525- await checkConnection ( true ) ;
538+ if ( affectsConfiguration ( "intersystems.servers" ) ) {
539+ // Gather the server names previously resolved
540+ const resolvedServers : string [ ] = [ ] ;
541+ resolvedConnSpecs . forEach ( ( v , k ) => resolvedServers . push ( k ) ) ;
542+ // Clear the cache
543+ resolvedConnSpecs . clear ( ) ;
544+ // Resolve them again, sequentially in case user needs to be prompted for credentials
545+ for await ( const serverName of resolvedServers ) {
546+ await resolveConnectionSpec ( serverName ) ;
547+ }
548+ }
549+ // Check connections sequentially for each workspace folder
550+ let refreshFilesExplorer = false ;
551+ for await ( const folder of vscode . workspace . workspaceFolders ) {
552+ if ( schemas . includes ( folder . uri . scheme ) ) {
553+ refreshFilesExplorer = true ;
554+ }
555+ try {
556+ await checkConnection ( true , folder . uri ) ;
557+ } catch ( _ ) {
558+ continue ;
559+ }
560+ }
526561 explorerProvider . refresh ( ) ;
562+ if ( refreshFilesExplorer ) {
563+ // This unavoidably switches to the File Explorer view, so only do it if isfs folders were found
564+ vscode . commands . executeCommand ( "workbench.files.action.refreshFilesExplorer" ) ;
565+ }
527566 }
528567 } ) ;
529568 vscode . window . onDidCloseTerminal ( ( t ) => {
@@ -548,7 +587,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
548587 } ) ;
549588
550589 vscode . window . onDidChangeActiveTextEditor ( async ( textEditor : vscode . TextEditor ) => {
551- await checkConnection ( ) ;
590+ await checkConnection ( false , textEditor ?. document . uri ) ;
552591 posPanel . text = "" ;
553592 if ( textEditor ?. document . fileName . endsWith ( ".xml" ) && config ( "autoPreviewXML" ) ) {
554593 return xml2doc ( context , textEditor ) ;
@@ -712,7 +751,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
712751 const workspaceFolder = currentWorkspaceFolder ( ) ;
713752 if ( workspaceFolder && workspaceFolder !== workspaceState . get < string > ( "workspaceFolder" ) ) {
714753 workspaceState . update ( "workspaceFolder" , workspaceFolder ) ;
715- await checkConnection ( ) ;
754+ await checkConnection ( false , editor ?. document . uri ) ;
716755 }
717756 }
718757 } ) ,
0 commit comments