@@ -163,6 +163,8 @@ export function getXmlUri(uri: vscode.Uri): vscode.Uri {
163
163
}
164
164
let reporter : TelemetryReporter = null ;
165
165
166
+ export let checkingConnection = false ;
167
+
166
168
let serverManagerApi : any ;
167
169
168
170
// 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 {
191
193
}
192
194
193
195
export 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
+
194
201
const { apiTarget, configName } = connectionTarget ( uri ) ;
195
202
if ( clearCookies ) {
196
203
/// clean-up cached values
@@ -268,7 +275,8 @@ export async function checkConnection(clearCookies = false, uri?: vscode.Uri): P
268
275
disableConnection ( configName ) ;
269
276
return ;
270
277
}
271
- api
278
+ checkingConnection = true ;
279
+ return api
272
280
. serverInfo ( )
273
281
. then ( ( info ) => {
274
282
panel . text = api . connInfo ;
@@ -279,6 +287,7 @@ export async function checkConnection(clearCookies = false, uri?: vscode.Uri): P
279
287
serverVersion : info . result . content . version ,
280
288
healthshare : hasHS ? "yes" : "no" ,
281
289
} ) ;
290
+ return ;
282
291
} )
283
292
. catch ( ( error ) => {
284
293
let message = error . message ;
@@ -324,10 +333,13 @@ export async function checkConnection(clearCookies = false, uri?: vscode.Uri): P
324
333
throw error ;
325
334
} )
326
335
. 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 ) ;
331
343
} ) ;
332
344
}
333
345
@@ -487,7 +499,8 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
487
499
const uri = oneToCheck [ 1 ] ;
488
500
const serverName = uri . scheme === "file" ? config ( "conn" , configName ) . server : configName ;
489
501
await resolveConnectionSpec ( serverName ) ;
490
- await checkConnection ( true , uri ) ;
502
+ // Ignore any failure
503
+ checkConnection ( true , uri ) . finally ( ) ;
491
504
}
492
505
493
506
vscode . workspace . onDidChangeWorkspaceFolders ( async ( { added, removed } ) => {
@@ -522,8 +535,34 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
522
535
523
536
vscode . workspace . onDidChangeConfiguration ( async ( { affectsConfiguration } ) => {
524
537
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
+ }
526
561
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
+ }
527
566
}
528
567
} ) ;
529
568
vscode . window . onDidCloseTerminal ( ( t ) => {
@@ -548,7 +587,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
548
587
} ) ;
549
588
550
589
vscode . window . onDidChangeActiveTextEditor ( async ( textEditor : vscode . TextEditor ) => {
551
- await checkConnection ( ) ;
590
+ await checkConnection ( false , textEditor ?. document . uri ) ;
552
591
posPanel . text = "" ;
553
592
if ( textEditor ?. document . fileName . endsWith ( ".xml" ) && config ( "autoPreviewXML" ) ) {
554
593
return xml2doc ( context , textEditor ) ;
@@ -712,7 +751,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
712
751
const workspaceFolder = currentWorkspaceFolder ( ) ;
713
752
if ( workspaceFolder && workspaceFolder !== workspaceState . get < string > ( "workspaceFolder" ) ) {
714
753
workspaceState . update ( "workspaceFolder" , workspaceFolder ) ;
715
- await checkConnection ( ) ;
754
+ await checkConnection ( false , editor ?. document . uri ) ;
716
755
}
717
756
}
718
757
} ) ,
0 commit comments