@@ -327,11 +327,14 @@ export default class ConnectionController {
327327 this . _connectingConnectionId = connectionId ;
328328 this . eventEmitter . emit ( DataServiceEventTypes . CONNECTIONS_DID_CHANGE ) ;
329329
330+ const prevConnectionId = this . _currentConnectionId ;
331+ const nextConnectionName = this . getSavedConnectionName ( connectionId ) ;
332+
330333 if ( this . _activeDataService ) {
331334 log . info ( 'Disconnecting from the previous connection...' , {
332335 connectionId : this . _currentConnectionId ,
333336 } ) ;
334- await this . disconnect ( ) ;
337+ await this . disconnect ( true ) ;
335338 }
336339
337340 if ( connectionAttempt . isClosed ( ) ) {
@@ -350,7 +353,7 @@ export default class ConnectionController {
350353 throw new Error ( 'Connect failed: connectionOptions are missing.' ) ;
351354 }
352355
353- this . _statusView . showMessage ( ' Connecting to MongoDB ...' ) ;
356+ this . _statusView . showMessage ( ` Connecting to ${ nextConnectionName } ...` ) ;
354357 log . info ( 'Connecting to MongoDB...' , {
355358 connectionInfo : JSON . stringify (
356359 extractSecrets ( this . _connections [ connectionId ] ) . connectionInfo
@@ -418,7 +421,20 @@ export default class ConnectionController {
418421 }
419422
420423 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+ }
422438
423439 dataService . addReauthenticationHandler (
424440 this . _reauthenticationHandler . bind ( this )
@@ -566,12 +582,17 @@ export default class ConnectionController {
566582 }
567583 }
568584
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 > {
570590 log . info (
571591 'Disconnect called, currently connected to' ,
572592 this . _currentConnectionId
573593 ) ;
574594
595+ const disconnectingConnectionId = this . _currentConnectionId ;
575596 this . _currentConnectionId = null ;
576597 this . _disconnecting = true ;
577598
@@ -586,12 +607,24 @@ export default class ConnectionController {
586607 return false ;
587608 }
588609
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+ ) ;
590617
591618 try {
592619 // Disconnect from the active connection.
593620 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+
595628 this . _activeDataService = null ;
596629
597630 void vscode . commands . executeCommand (
@@ -607,7 +640,7 @@ export default class ConnectionController {
607640 } catch ( error ) {
608641 // Show an error, however we still reset the active connection to free up the extension.
609642 void vscode . window . showErrorMessage (
610- ' An error occurred while disconnecting from the current connection.'
643+ ` An error occurred while disconnecting from ${ disconnectingConnectionName } .`
611644 ) ;
612645 }
613646
0 commit comments