Skip to content

Commit

Permalink
master: Fixes #328
Browse files Browse the repository at this point in the history
  • Loading branch information
mtxr committed Aug 25, 2019
1 parent a9edf43 commit 6584f1b
Showing 1 changed file with 32 additions and 25 deletions.
57 changes: 32 additions & 25 deletions packages/plugins/connection-manager/language-server.ts
Expand Up @@ -118,36 +118,43 @@ export default class ConnectionManagerPlugin implements SQLTools.LanguageServerP
if (!req || !req.conn) {
return undefined;
}
let c = this.getConnectionInstance(req.conn) || new Connection(req.conn, this.server.telemetry);

if (req.password) c.setPassword(req.password);
const progressBase = {
id: `progress:${c.getId()}`,
title: c.getName(),
}
this.server.sendNotification(ProgressNotificationStart, { ...progressBase, message: 'Connecting....' });
return c
.connect()
.then(async () => {
this.server.store.dispatch(actions.Connect(c));
let c = this.getConnectionInstance(req.conn);
let progressBase;
try {
if (c) {
await this._loadConnectionData(c);
this.server.sendNotification(ProgressNotificationComplete, { ...progressBase, message: 'Connected!' });
return c.serialize();
})
.catch(e => {
this.server.sendNotification(ProgressNotificationComplete, progressBase);
e = decorateException(e, { conn: req.conn });
if (e.data && e.data.notification) {
if (req.conn.dialect && DependencyManager.runningJobs.includes(req.conn.dialect)) {
return void this.server.sendNotification(DependeciesAreBeingInstalledNotification, e.data.args);
}
return void this.server.sendNotification(e.data.notification, e.data.args);
}
c = new Connection(req.conn, this.server.telemetry);
progressBase = {
id: `progress:${c.getId()}`,
title: c.getName(),
}

if (req.password) c.setPassword(req.password);

this.server.store.dispatch(actions.Connect(c));

this.server.sendNotification(ProgressNotificationStart, { ...progressBase, message: 'Connecting....' });
await c.connect()
await this._loadConnectionData(c);
this.server.sendNotification(ProgressNotificationComplete, { ...progressBase, message: 'Connected!' });
return c.serialize();
} catch (e) {
this.server.store.dispatch(actions.Disconnect(c));
progressBase && this.server.sendNotification(ProgressNotificationComplete, progressBase);
e = decorateException(e, { conn: req.conn });
if (e.data && e.data.notification) {
if (req.conn.dialect && DependencyManager.runningJobs.includes(req.conn.dialect)) {
return void this.server.sendNotification(DependeciesAreBeingInstalledNotification, e.data.args);
}
return void this.server.sendNotification(e.data.notification, e.data.args);
}

this.server.telemetry.registerException(e);
this.server.telemetry.registerException(e);

throw e;
});
throw e;
}
};

private clientRequestConnectionHandler: RequestHandler<typeof GetConnectionsRequest> = ({ connectedOnly } = {}) => {
Expand Down

0 comments on commit 6584f1b

Please sign in to comment.