@@ -327,11 +327,14 @@ export default class ConnectionController {
327
327
this . _connectingConnectionId = connectionId ;
328
328
this . eventEmitter . emit ( DataServiceEventTypes . CONNECTIONS_DID_CHANGE ) ;
329
329
330
+ const prevConnectionId = this . _currentConnectionId ;
331
+ const nextConnectionName = this . getSavedConnectionName ( connectionId ) ;
332
+
330
333
if ( this . _activeDataService ) {
331
334
log . info ( 'Disconnecting from the previous connection...' , {
332
335
connectionId : this . _currentConnectionId ,
333
336
} ) ;
334
- await this . disconnect ( ) ;
337
+ await this . disconnect ( true ) ;
335
338
}
336
339
337
340
if ( connectionAttempt . isClosed ( ) ) {
@@ -350,7 +353,7 @@ export default class ConnectionController {
350
353
throw new Error ( 'Connect failed: connectionOptions are missing.' ) ;
351
354
}
352
355
353
- this . _statusView . showMessage ( ' Connecting to MongoDB ...' ) ;
356
+ this . _statusView . showMessage ( ` Connecting to ${ nextConnectionName } ...` ) ;
354
357
log . info ( 'Connecting to MongoDB...' , {
355
358
connectionInfo : JSON . stringify (
356
359
extractSecrets ( this . _connections [ connectionId ] ) . connectionInfo
@@ -418,7 +421,20 @@ export default class ConnectionController {
418
421
}
419
422
420
423
log . info ( 'Successfully connected' , { connectionId } ) ;
421
- void vscode . window . showInformationMessage ( 'MongoDB connection successful.' ) ;
424
+
425
+ if ( prevConnectionId ) {
426
+ const prevConnectionName = prevConnectionId
427
+ ? this . getSavedConnectionName ( prevConnectionId )
428
+ : 'MongoDB server' ;
429
+
430
+ void vscode . window . showInformationMessage (
431
+ `Disconnected from ${ prevConnectionName } and connected to ${ nextConnectionName } .`
432
+ ) ;
433
+ } else {
434
+ void vscode . window . showInformationMessage (
435
+ `Connected to ${ nextConnectionName } .`
436
+ ) ;
437
+ }
422
438
423
439
dataService . addReauthenticationHandler (
424
440
this . _reauthenticationHandler . bind ( this )
@@ -566,12 +582,17 @@ export default class ConnectionController {
566
582
}
567
583
}
568
584
569
- async disconnect ( ) : Promise < boolean > {
585
+ /**
586
+ * @param quiet Don't display non-error notifications to the user.
587
+ * @returns If we disconnected from MongoDB successfully.
588
+ */
589
+ async disconnect ( quiet = false ) : Promise < boolean > {
570
590
log . info (
571
591
'Disconnect called, currently connected to' ,
572
592
this . _currentConnectionId
573
593
) ;
574
594
595
+ const disconnectingConnectionId = this . _currentConnectionId ;
575
596
this . _currentConnectionId = null ;
576
597
this . _disconnecting = true ;
577
598
@@ -586,12 +607,24 @@ export default class ConnectionController {
586
607
return false ;
587
608
}
588
609
589
- this . _statusView . showMessage ( 'Disconnecting from current connection...' ) ;
610
+ const disconnectingConnectionName = disconnectingConnectionId
611
+ ? this . getSavedConnectionName ( disconnectingConnectionId )
612
+ : 'MongoDB server' ;
613
+
614
+ this . _statusView . showMessage (
615
+ `Disconnecting from ${ disconnectingConnectionName } ...`
616
+ ) ;
590
617
591
618
try {
592
619
// Disconnect from the active connection.
593
620
await this . _activeDataService . disconnect ( ) ;
594
- void vscode . window . showInformationMessage ( 'MongoDB disconnected.' ) ;
621
+
622
+ if ( ! quiet ) {
623
+ void vscode . window . showInformationMessage (
624
+ `Disconnected from ${ disconnectingConnectionName } .`
625
+ ) ;
626
+ }
627
+
595
628
this . _activeDataService = null ;
596
629
597
630
void vscode . commands . executeCommand (
@@ -607,7 +640,7 @@ export default class ConnectionController {
607
640
} catch ( error ) {
608
641
// Show an error, however we still reset the active connection to free up the extension.
609
642
void vscode . window . showErrorMessage (
610
- ' An error occurred while disconnecting from the current connection.'
643
+ ` An error occurred while disconnecting from ${ disconnectingConnectionName } .`
611
644
) ;
612
645
}
613
646
0 commit comments