in src/controllers/connectionManager.ts [585:634]
public connect(fileUri: string, connectionCreds: Interfaces.IConnectionCredentials): Promise<boolean> {
const self = this;
return new Promise<boolean>((resolve, reject) => {
let connectionInfo: ConnectionInfo = new ConnectionInfo();
connectionInfo.extensionTimer = new Utils.Timer();
connectionInfo.intelliSenseTimer = new Utils.Timer();
connectionInfo.credentials = connectionCreds;
connectionInfo.connecting = true;
this._connections[fileUri] = connectionInfo;
// Note: must call flavor changed before connecting, or the timer showing an animation doesn't occur
if (self.statusView) {
self.statusView.languageFlavorChanged(fileUri, Constants.pgsqlProviderName);
self.statusView.connecting(fileUri, connectionCreds);
self.statusView.languageFlavorChanged(fileUri, Constants.pgsqlProviderName);
}
self.vscodeWrapper.logToOutputChannel(
Utils.formatString(LocalizedConstants.msgConnecting, connectionCreds.host, fileUri)
);
// Setup the handler for the connection complete notification to call
connectionInfo.connectHandler = ((connectResult, error) => {
if (error) {
reject(error);
} else {
resolve(connectResult);
}
});
// package connection details for request message
const connectionDetails = ConnectionCredentials.createConnectionDetails(connectionCreds);
let connectParams = new ConnectionContracts.ConnectParams();
connectParams.ownerUri = fileUri;
connectParams.connection = connectionDetails;
connectionInfo.serviceTimer = new Utils.Timer();
// send connection request message to service host
self.client.sendRequest(ConnectionContracts.ConnectionRequest.type, connectParams).then((result) => {
if (!result) {
// Failed to process connect request
resolve(false);
}
}, err => {
// Catch unexpected errors and return over the Promise reject callback
reject(err);
});
});
}