#3224 Fix extra connections populating MRU List (#4368)

* Modify where we add active connections so that we can use the saveTheConnection option to decide whether to add a connection to the MRU. This was necessary because the old location was called from onConnectionComplete which is sent by the SqlToolsService - and that doesn't get any UI related information like the options. The new location is still only called after the connection completes and will be added only if the connection succeeds.

Added new test and updated existing tests to handle new logic (plus a bit of async-refactoring).

* Fix couple spacing issues

* Add logic back in to short-circuit if we already have the connection in the active connections list.

* Fix spaces -> tabs
This commit is contained in:
Charles Gagnon
2019-03-12 14:05:50 -07:00
committed by GitHub
parent e783aeab66
commit 9fdeec6128
6 changed files with 118 additions and 94 deletions

View File

@@ -464,6 +464,12 @@ export class ConnectionManagementService extends Disposable implements IConnecti
}
this.createNewConnection(uri, connection).then(connectionResult => {
if (connectionResult && connectionResult.connected) {
// The connected succeeded so add it to our active connections now, optionally adding it to the MRU based on
// the options.saveTheConnection setting
let connectionMgmtInfo = this._connectionStatusManager.findConnection(uri);
let activeConnection = connectionMgmtInfo.connectionProfile;
this.tryAddActiveConnection(connectionMgmtInfo, activeConnection, options.saveTheConnection);
if (callbacks.onConnectSuccess) {
callbacks.onConnectSuccess(options.params);
}
@@ -860,9 +866,9 @@ export class ConnectionManagementService extends Disposable implements IConnecti
/**
* Add a connection to the active connections list.
*/
private tryAddActiveConnection(connectionManagementInfo: ConnectionManagementInfo, newConnection: IConnectionProfile, isConnectionToDefaultDb: boolean): void {
private tryAddActiveConnection(connectionManagementInfo: ConnectionManagementInfo, newConnection: IConnectionProfile, addToMru: boolean): void {
if (newConnection) {
this._connectionStore.addActiveConnection(newConnection, isConnectionToDefaultDb)
this._connectionStore.addActiveConnection(newConnection, addToMru)
.then(() => {
connectionManagementInfo.connectHandler(true);
}, err => {
@@ -896,10 +902,6 @@ export class ConnectionManagementService extends Disposable implements IConnecti
let connection = this._connectionStatusManager.onConnectionComplete(info);
if (info.connectionId) {
let isConnectionToDefaultDb = false;
if (connection.connectionProfile && (!connection.connectionProfile.databaseName || connection.connectionProfile.databaseName.trim() === '')) {
isConnectionToDefaultDb = true;
}
if (info.connectionSummary && info.connectionSummary.databaseName) {
this._connectionStatusManager.updateDatabaseName(info);
}
@@ -907,8 +909,6 @@ export class ConnectionManagementService extends Disposable implements IConnecti
connection.extensionTimer.stop();
connection.connectHandler(true);
let activeConnection = connection.connectionProfile;
self.tryAddActiveConnection(connection, activeConnection, isConnectionToDefaultDb);
self.addTelemetryForConnection(connection);
if (self._connectionStatusManager.isDefaultTypeUri(info.ownerUri)) {