Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 9 additions & 27 deletions src/classes/localConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { commands } from "vscode";
import { ext } from "../extensionVariables";
import { QueryResult, QueryResultType } from "../models/queryResult";
import { ServerObject } from "../models/serverObject";
import { delay, getAutoFocusOutputOnEntrySetting } from "../utils/core";
import { delay } from "../utils/core";
import { convertStringToArray, handleQueryResults } from "../utils/execution";
import { MessageKind, notify } from "../utils/notifications";
import { queryWrapper } from "../utils/queryUtils";
Expand Down Expand Up @@ -83,47 +83,41 @@ export class LocalConnection {
public async connect(
callback: nodeq.AsyncValueCallback<LocalConnection>,
): Promise<void> {
if (this.connection && this.connected) return;

const options = await this.getCustomAuthOptions();

nodeq.connect(options, (err, conn) => {
if (err || !conn) {
ext.serverProvider.reload();

notify(
`Connection to server ${this.options.host}:${this.options.port} failed.`,
MessageKind.ERROR,
{ logger, params: err },
);

return;
}

conn.addListener("close", () => {
commands.executeCommand("kdb.connections.disconnect", this.connLabel);
notify(
`Connection closed: ${this.options.host}:${this.options.port}`,
MessageKind.DEBUG,
{ logger },
);
if (getAutoFocusOutputOnEntrySetting()) {
ext.outputChannel.show(true);
}
});

if (this.connection && this.connected) {
this.connection.close(() => {
this.onConnect(err, conn, callback);
});
} else {
this.onConnect(err, conn, callback);
}

this.connected = false;
this.connection = conn;
this.connected = true;
this.update();
callback(err, this);
});
}

public disconnect(): void {
if (this.connected) {
this.connection?.close();
this.connection = undefined;
this.connected = false;
}
}
Expand Down Expand Up @@ -378,18 +372,6 @@ export class LocalConnection {
});
}

private onConnect(
err: Error | undefined,
conn: nodeq.Connection,
callback: nodeq.AsyncValueCallback<LocalConnection>,
): void {
this.connected = true;
this.connection = conn;

this.update();
callback(err, this);
}

async getCustomAuthOptions(): Promise<nodeq.ConnectionParameters> {
if (ext.customAuth) {
const { kdb } = await ext.customAuth.auth({
Expand Down
4 changes: 4 additions & 0 deletions src/classes/replConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -751,4 +751,8 @@ export class ReplConnection {

return repl;
}

static dispose() {
Array.from(this.repls.values()).forEach((repl) => repl.close());
}
}
3 changes: 3 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
TransportKind,
} from "vscode-languageclient/node";

import { ReplConnection } from "./classes/replConnection";
import { connectBuildTools, lintCommand } from "./commands/buildToolsCommand";
import { connectClientCommands } from "./commands/clientCommand";
import {
Expand Down Expand Up @@ -1016,6 +1017,8 @@ function registerAllExtensionCommands(): void {
}

export async function deactivate(): Promise<void> {
ReplConnection.dispose();

await Telemetry.dispose();

if (!ext.client) {
Expand Down