Skip to content

Commit e22d526

Browse files
committed
fix: send 1 notification switch connection
1 parent 6357efa commit e22d526

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

src/connectionController.ts

+24-5
Original file line numberDiff line numberDiff line change
@@ -393,8 +393,10 @@ export default class ConnectionController {
393393
this._connectingConnectionId = connectionId;
394394
this.eventEmitter.emit(DataServiceEventTypes.CONNECTIONS_DID_CHANGE);
395395

396-
if (this._activeDataService) {
397-
await this.disconnect();
396+
const oldConnectionId = this._currentConnectionId;
397+
398+
if (oldConnectionId) {
399+
await this.disconnect(true);
398400
}
399401

400402
this._statusView.showMessage('Connecting to MongoDB...');
@@ -433,7 +435,17 @@ export default class ConnectionController {
433435
}
434436

435437
log.info('Successfully connected');
436-
void vscode.window.showInformationMessage('MongoDB connection successful.');
438+
439+
if (oldConnectionId) {
440+
const currentConnectionName = oldConnectionId
441+
? this.getSavedConnectionName(oldConnectionId)
442+
: 'previous server';
443+
const nextConnectionName = this.getSavedConnectionName(connectionId);
444+
445+
void vscode.window.showInformationMessage(`Disconnected from ${currentConnectionName} and connected to ${nextConnectionName}.`);
446+
} else {
447+
void vscode.window.showInformationMessage('MongoDB connection successful.');
448+
}
437449

438450
this._activeDataService = newDataService;
439451
this._currentConnectionId = connectionId;
@@ -491,7 +503,11 @@ export default class ConnectionController {
491503
}
492504
}
493505

494-
async disconnect(): Promise<boolean> {
506+
/**
507+
* @param quiet Don't display non-error notifications to the user.
508+
* @returns If we disconnected from MongoDB succesfully.
509+
*/
510+
async disconnect(quiet = false): Promise<boolean> {
495511
log.info(
496512
'Disconnect called, currently connected to:',
497513
this._currentConnectionId
@@ -516,8 +532,11 @@ export default class ConnectionController {
516532
try {
517533
// Disconnect from the active connection.
518534
await this._activeDataService.disconnect();
519-
void vscode.window.showInformationMessage('MongoDB disconnected.');
520535
this._activeDataService = null;
536+
537+
if (!quiet) {
538+
void vscode.window.showInformationMessage('MongoDB disconnected.');
539+
}
521540
} catch (error) {
522541
// Show an error, however we still reset the active connection to free up the extension.
523542
void vscode.window.showErrorMessage(

0 commit comments

Comments
 (0)