Skip to content

Commit c719ac0

Browse files
authored
Merge pull request #689 from KxSystems/ee-fixes
[fix] for connect after close for my q
2 parents e628f0e + 5e55eef commit c719ac0

File tree

3 files changed

+16
-27
lines changed

3 files changed

+16
-27
lines changed

src/classes/localConnection.ts

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { commands } from "vscode";
1919
import { ext } from "../extensionVariables";
2020
import { QueryResult, QueryResultType } from "../models/queryResult";
2121
import { ServerObject } from "../models/serverObject";
22-
import { delay, getAutoFocusOutputOnEntrySetting } from "../utils/core";
22+
import { delay } from "../utils/core";
2323
import { convertStringToArray, handleQueryResults } from "../utils/execution";
2424
import { MessageKind, notify } from "../utils/notifications";
2525
import { queryWrapper } from "../utils/queryUtils";
@@ -83,47 +83,41 @@ export class LocalConnection {
8383
public async connect(
8484
callback: nodeq.AsyncValueCallback<LocalConnection>,
8585
): Promise<void> {
86+
if (this.connection && this.connected) return;
87+
8688
const options = await this.getCustomAuthOptions();
8789

8890
nodeq.connect(options, (err, conn) => {
8991
if (err || !conn) {
9092
ext.serverProvider.reload();
91-
9293
notify(
9394
`Connection to server ${this.options.host}:${this.options.port} failed.`,
9495
MessageKind.ERROR,
9596
{ logger, params: err },
9697
);
97-
9898
return;
9999
}
100+
100101
conn.addListener("close", () => {
101102
commands.executeCommand("kdb.connections.disconnect", this.connLabel);
102103
notify(
103104
`Connection closed: ${this.options.host}:${this.options.port}`,
104105
MessageKind.DEBUG,
105106
{ logger },
106107
);
107-
if (getAutoFocusOutputOnEntrySetting()) {
108-
ext.outputChannel.show(true);
109-
}
110108
});
111109

112-
if (this.connection && this.connected) {
113-
this.connection.close(() => {
114-
this.onConnect(err, conn, callback);
115-
});
116-
} else {
117-
this.onConnect(err, conn, callback);
118-
}
119-
120-
this.connected = false;
110+
this.connection = conn;
111+
this.connected = true;
112+
this.update();
113+
callback(err, this);
121114
});
122115
}
123116

124117
public disconnect(): void {
125118
if (this.connected) {
126119
this.connection?.close();
120+
this.connection = undefined;
127121
this.connected = false;
128122
}
129123
}
@@ -378,18 +372,6 @@ export class LocalConnection {
378372
});
379373
}
380374

381-
private onConnect(
382-
err: Error | undefined,
383-
conn: nodeq.Connection,
384-
callback: nodeq.AsyncValueCallback<LocalConnection>,
385-
): void {
386-
this.connected = true;
387-
this.connection = conn;
388-
389-
this.update();
390-
callback(err, this);
391-
}
392-
393375
async getCustomAuthOptions(): Promise<nodeq.ConnectionParameters> {
394376
if (ext.customAuth) {
395377
const { kdb } = await ext.customAuth.auth({

src/classes/replConnection.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,4 +751,8 @@ export class ReplConnection {
751751

752752
return repl;
753753
}
754+
755+
static dispose() {
756+
Array.from(this.repls.values()).forEach((repl) => repl.close());
757+
}
754758
}

src/extension.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
TransportKind,
2222
} from "vscode-languageclient/node";
2323

24+
import { ReplConnection } from "./classes/replConnection";
2425
import { connectBuildTools, lintCommand } from "./commands/buildToolsCommand";
2526
import { connectClientCommands } from "./commands/clientCommand";
2627
import {
@@ -1016,6 +1017,8 @@ function registerAllExtensionCommands(): void {
10161017
}
10171018

10181019
export async function deactivate(): Promise<void> {
1020+
ReplConnection.dispose();
1021+
10191022
await Telemetry.dispose();
10201023

10211024
if (!ext.client) {

0 commit comments

Comments
 (0)