From 98bc42764f59f44b48f416c518c6d8463cbd804b Mon Sep 17 00:00:00 2001 From: Philip Carneiro Date: Thu, 23 May 2024 10:11:10 +0100 Subject: [PATCH 01/12] update axios --- package-lock.json | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4e36204f..e6236a62 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,7 @@ "@vscode/webview-ui-toolkit": "^1.4.0", "@windozer/node-q": "^2.6.0", "ag-grid-community": "^31.3.1", - "axios": "^1.7.0", + "axios": "^1.7.2", "chevrotain": "^10.5.0", "csv-parser": "^3.0.0", "extract-zip": "^2.0.1", @@ -1670,9 +1670,9 @@ "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" }, "node_modules/axios": { - "version": "1.7.0", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.0.tgz", - "integrity": "sha512-IiB0wQeKyPRdsFVhBgIo31FbzOyf2M6wYl7/NVutFwFBRMiAbjNiydJIHKeLmPugF4kJLfA1uWZ82Is2QzqqFA==", + "version": "1.7.2", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.2.tgz", + "integrity": "sha512-2A8QhOMrbomlDuiLeK9XibIBzuHeRcqqNOHp0Cyp5EoJ1IFDh+XZH3A6BkXtv0K4gFGCI0Y4BM7B1wOEi0Rmgw==", "dependencies": { "follow-redirects": "^1.15.6", "form-data": "^4.0.0", diff --git a/package.json b/package.json index 58c6fc73..6eaa3e62 100644 --- a/package.json +++ b/package.json @@ -837,7 +837,7 @@ "@vscode/webview-ui-toolkit": "^1.4.0", "@windozer/node-q": "^2.6.0", "ag-grid-community": "^31.3.1", - "axios": "^1.7.0", + "axios": "^1.7.2", "chevrotain": "^10.5.0", "csv-parser": "^3.0.0", "extract-zip": "^2.0.1", From e5090132004e7cc7ee318da6ab8bce18b03d5e14 Mon Sep 17 00:00:00 2001 From: Philip Carneiro Date: Thu, 23 May 2024 10:29:42 +0100 Subject: [PATCH 02/12] removed obsolete command --- package.json | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/package.json b/package.json index 6eaa3e62..bc1c097f 100644 --- a/package.json +++ b/package.json @@ -292,11 +292,6 @@ "command": "kdb.enableTLS", "title": "Enable TLS" }, - { - "category": "KX", - "command": "kdb.insightsConnect", - "title": "Connect to Insights" - }, { "category": "KX", "command": "kdb.insightsRemove", @@ -521,10 +516,6 @@ ], "menus": { "commandPalette": [ - { - "command": "kdb.insightsConnect", - "when": "false" - }, { "command": "kdb.insightsRemove", "when": "false" @@ -634,7 +625,7 @@ "view/item/context": [ { "command": "kdb.connect", - "when": "view == kdb-servers && viewItem not in kdb.connected && viewItem in kdb.rootNodes", + "when": "view == kdb-servers && viewItem not in kdb.connected", "group": "connection@1" }, { @@ -652,11 +643,6 @@ "when": "view == kdb-servers && viewItem not in kdb.insightsNodes && viewItem in kdb.kdbNodesWithoutTls && viewItem not in kdb.local", "group": "connection@4" }, - { - "command": "kdb.insightsConnect", - "when": "view == kdb-servers && viewItem not in kdb.connected && viewItem in kdb.insightsNodes", - "group": "connection@0" - }, { "command": "kdb.insightsRemove", "when": "view == kdb-servers && viewItem in kdb.insightsNodes", From a5e073821a758314a18f04b64056184eb96d63f7 Mon Sep 17 00:00:00 2001 From: Philip Carneiro Date: Thu, 23 May 2024 10:30:04 +0100 Subject: [PATCH 03/12] change to get connLabel instead connNode --- src/commands/serverCommand.ts | 9 +++++---- src/extension.ts | 15 ++++++--------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/commands/serverCommand.ts b/src/commands/serverCommand.ts index 274e65b7..e7aef06c 100644 --- a/src/commands/serverCommand.ts +++ b/src/commands/serverCommand.ts @@ -258,13 +258,14 @@ export async function removeConnection(viewItem: KdbNode | InsightsNode) { await connMngService.removeConnection(viewItem); } -export async function connect(viewItem: KdbNode | InsightsNode): Promise { +export async function connect(connLabel: string): Promise { const connMngService = new ConnectionManagementService(); commands.executeCommand("kdb-results.focus"); ExecutionConsole.start(); - // handle cleaning up existing connection - if (ext.activeConnection !== undefined) { - DataSourcesPanel.close(); + const viewItem = connMngService.retrieveConnection(connLabel); + if (viewItem === undefined) { + window.showErrorMessage("Connection not found"); + return; } const isKdbNode = viewItem instanceof KdbNode; diff --git a/src/extension.ts b/src/extension.ts index 1120b4fc..ea5fd364 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -185,9 +185,12 @@ export async function activate(context: ExtensionContext) { commands.registerCommand("kdb.datasource.import.ds", async () => { await importOldDSFiles(); }), - commands.registerCommand("kdb.connect", async (viewItem: KdbNode) => { - await connect(viewItem); - }), + commands.registerCommand( + "kdb.connect", + async (viewItem: KdbNode | InsightsNode) => { + await connect(viewItem.label); + }, + ), commands.registerCommand( "kdb.active.connection", async (viewItem: KdbNode) => { @@ -197,12 +200,6 @@ export async function activate(context: ExtensionContext) { commands.registerCommand("kdb.enableTLS", async (viewItem: KdbNode) => { await enableTLS(viewItem.children[0]); }), - commands.registerCommand( - "kdb.insightsConnect", - async (viewItem: InsightsNode) => { - await connect(viewItem); - }, - ), commands.registerCommand( "kdb.insightsRemove", async (viewItem: InsightsNode) => { From e9c35ff08f1d4c2352a52cbe561304d8d67359f4 Mon Sep 17 00:00:00 2001 From: Philip Carneiro Date: Thu, 23 May 2024 10:58:46 +0100 Subject: [PATCH 04/12] add command to connect via string --- package.json | 9 +++++++++ src/extension.ts | 6 ++++++ src/utils/core.ts | 14 ++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/package.json b/package.json index bc1c097f..eadb4f7c 100644 --- a/package.json +++ b/package.json @@ -276,6 +276,11 @@ "command": "kdb.connect", "title": "Connect server" }, + { + "category": "KX", + "command": "kdb.connect.via.dialog", + "title": "Connect server" + }, { "category": "KX", "command": "kdb.active.connection", @@ -540,6 +545,10 @@ "command": "kdb.connect", "when": "false" }, + { + "command": "kdb.connect.via.dialog", + "when": "false" + }, { "command": "kdb.active.connection", "when": "false" diff --git a/src/extension.ts b/src/extension.ts index ea5fd364..29c92ef8 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -191,6 +191,12 @@ export async function activate(context: ExtensionContext) { await connect(viewItem.label); }, ), + commands.registerCommand( + "kdb.connect.via.dialog", + async (connLabel: string) => { + await connect(connLabel); + }, + ), commands.registerCommand( "kdb.active.connection", async (viewItem: KdbNode) => { diff --git a/src/utils/core.ts b/src/utils/core.ts index 80248166..3c7d738f 100644 --- a/src/utils/core.ts +++ b/src/utils/core.ts @@ -250,6 +250,20 @@ export function getServerAlias(serverList: ServerDetails[]): void { }); } +export function offerConnectAction(connLabel: string): void { + window + .showInformationMessage( + `You aren't connected to ${connLabel}, would you like to connect?`, + "Connect", + "Cancel", + ) + .then(async (result) => { + if (result === "Connect") { + await commands.executeCommand("kdb.connect.via.dialog", connLabel); + } + }); +} + export function getInsightsAlias(insightsList: InsightDetails[]): void { insightsList.forEach((x) => { ext.kdbConnectionAliasList.push(x.alias); From fefaf6a4c6144c5e7f5c7a59766ac9a96c841615 Mon Sep 17 00:00:00 2001 From: Philip Carneiro Date: Thu, 23 May 2024 11:01:52 +0100 Subject: [PATCH 05/12] fix run and populate ds --- src/commands/dataSourceCommand.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/commands/dataSourceCommand.ts b/src/commands/dataSourceCommand.ts index ce5275b7..24196eae 100644 --- a/src/commands/dataSourceCommand.ts +++ b/src/commands/dataSourceCommand.ts @@ -45,6 +45,7 @@ import { Telemetry } from "../utils/telemetryClient"; import { LocalConnection } from "../classes/localConnection"; import { ConnectionManagementService } from "../services/connectionManagerService"; import { InsightsConnection } from "../classes/insightsConnection"; +import { offerConnectAction } from "../utils/core"; export async function addDataSource(): Promise { const kdbDataSourcesFolderPath = createKdbDataSourcesFolder(); @@ -92,7 +93,7 @@ export async function populateScratchpad( selectedConnection instanceof LocalConnection || !selectedConnection ) { - window.showErrorMessage("No Insights active connection found"); + offerConnectAction(connLabel); DataSourcesPanel.running = false; return; } @@ -123,7 +124,8 @@ export async function runDataSource( try { if (selectedConnection instanceof LocalConnection || !selectedConnection) { - throw new Error("The selected Insights Connection is not connected"); + offerConnectAction(connLabel); + return; } selectedConnection.getMeta(); if (!selectedConnection?.meta?.payload.assembly) { From d44eee6048a8b72c3c4962d9344353a4b5c7515f Mon Sep 17 00:00:00 2001 From: Philip Carneiro Date: Thu, 23 May 2024 11:08:20 +0100 Subject: [PATCH 06/12] fix refresh from DS --- src/services/connectionManagerService.ts | 9 ++++++++- src/services/dataSourceEditorProvider.ts | 7 ++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/services/connectionManagerService.ts b/src/services/connectionManagerService.ts index d5b7f40f..0d326b9f 100644 --- a/src/services/connectionManagerService.ts +++ b/src/services/connectionManagerService.ts @@ -329,7 +329,7 @@ export class ConnectionManagementService { } } - public async refreshGetMetas(): Promise { + public async refreshAllGetMetas(): Promise { if (ext.connectedConnectionList.length > 0) { const promises = ext.connectedConnectionList.map(async (connection) => { if (connection instanceof InsightsConnection) { @@ -339,4 +339,11 @@ export class ConnectionManagementService { await Promise.all(promises); } } + + public async refreshGetMeta(connLabel: string): Promise { + const connection = this.retrieveConnectedConnection(connLabel); + if (connection instanceof InsightsConnection) { + await connection.getMeta(); + } + } } diff --git a/src/services/dataSourceEditorProvider.ts b/src/services/dataSourceEditorProvider.ts index 42bcaf80..126831fd 100644 --- a/src/services/dataSourceEditorProvider.ts +++ b/src/services/dataSourceEditorProvider.ts @@ -40,6 +40,7 @@ import { import { InsightsConnection } from "../classes/insightsConnection"; import { MetaObjectPayload } from "../models/meta"; import { ConnectionManagementService } from "./connectionManagerService"; +import { offerConnectAction } from "../utils/core"; export class DataSourceEditorProvider implements CustomTextEditorProvider { public filenname = ""; @@ -156,8 +157,12 @@ export class DataSourceEditorProvider implements CustomTextEditorProvider { break; case DataSourceCommand.Refresh: const connMngService = new ConnectionManagementService(); - await connMngService.refreshGetMetas(); const selectedServer = getServerForUri(document.uri) || ""; + if (!connMngService.isConnected(selectedServer)) { + offerConnectAction(selectedServer); + break; + } + await connMngService.refreshGetMeta(selectedServer); this.cache.delete(selectedServer); updateWebview(); break; From 5fd4cd39c40b6d2ab0e4b0f8e045a9710c33c5ee Mon Sep 17 00:00:00 2001 From: Philip Carneiro Date: Thu, 23 May 2024 11:11:38 +0100 Subject: [PATCH 07/12] fix workbook --- src/commands/workspaceCommand.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/commands/workspaceCommand.ts b/src/commands/workspaceCommand.ts index 8c96e662..e73be999 100644 --- a/src/commands/workspaceCommand.ts +++ b/src/commands/workspaceCommand.ts @@ -32,6 +32,7 @@ import { InsightsNode, KdbNode } from "../services/kdbTreeProvider"; import { runQuery } from "./serverCommand"; import { ExecutionTypes } from "../models/execution"; import { importOldDsFiles, oldFilesExists } from "../utils/dataSource"; +import { offerConnectAction } from "../utils/core"; const connectionService = new ConnectionManagementService(); @@ -228,6 +229,7 @@ export async function activateConnectionForServer(server: string) { /* istanbul ignore next */ export async function runActiveEditor(type?: ExecutionTypes) { if (ext.activeTextEditor) { + const connMngService = new ConnectionManagementService(); const uri = ext.activeTextEditor.document.uri; const isWorkbook = uri.path.endsWith(".kdb.q"); @@ -238,6 +240,10 @@ export async function runActiveEditor(type?: ExecutionTypes) { if (!server) { server = ""; } + if (!connMngService.isConnected(server)) { + offerConnectAction(server); + return; + } const executorName = ext.activeTextEditor.document.fileName .split("/") .pop(); From b0a830df33822fd14c637d25a60dd7abe7051352 Mon Sep 17 00:00:00 2001 From: Philip Carneiro Date: Thu, 23 May 2024 11:15:38 +0100 Subject: [PATCH 08/12] fix for scratchpad - no workbook --- src/commands/serverCommand.ts | 2 +- src/commands/workspaceCommand.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/commands/serverCommand.ts b/src/commands/serverCommand.ts index e7aef06c..6a928b7e 100644 --- a/src/commands/serverCommand.ts +++ b/src/commands/serverCommand.ts @@ -335,7 +335,7 @@ export async function executeQuery( if (connLabel === "") { if (ext.activeConnection === undefined) { window.showErrorMessage( - "No active connection founded. Connect to one connection.", + "No active connection found. Connect to one connection.", ); //TODO ADD ERROR TO CONSOLE HERE return undefined; diff --git a/src/commands/workspaceCommand.ts b/src/commands/workspaceCommand.ts index e73be999..609ce94d 100644 --- a/src/commands/workspaceCommand.ts +++ b/src/commands/workspaceCommand.ts @@ -240,7 +240,7 @@ export async function runActiveEditor(type?: ExecutionTypes) { if (!server) { server = ""; } - if (!connMngService.isConnected(server)) { + if (!connMngService.isConnected(server) && isScratchpad(uri)) { offerConnectAction(server); return; } From 24ec2220e3c957bb8f894c6ec79d36104ccdb20f Mon Sep 17 00:00:00 2001 From: Philip Carneiro Date: Thu, 23 May 2024 11:19:06 +0100 Subject: [PATCH 09/12] fix refresh and add refresh tests --- test/suite/services.test.ts | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/test/suite/services.test.ts b/test/suite/services.test.ts index eb03773e..6a41fda8 100644 --- a/test/suite/services.test.ts +++ b/test/suite/services.test.ts @@ -1053,7 +1053,7 @@ describe("connectionManagerService", () => { }); }); - describe("refreshGetMetas", () => { + describe("refreshAllGetMetas && refreshGetMeta", () => { let getMetaStub: sinon.SinonStub; beforeEach(() => { getMetaStub = sinon.stub(insightsConn, "getMeta"); @@ -1063,14 +1063,24 @@ describe("connectionManagerService", () => { ext.connectedConnectionList.length = 0; }); - it("Should not refresh getMetas if connection is not InsightsConnection", async () => { - await connectionManagerService.refreshGetMetas(); + it("Should not refreshAllgetMetas if connection is not InsightsConnection", async () => { + await connectionManagerService.refreshAllGetMetas(); sinon.assert.notCalled(getMetaStub); }); - it("Should refresh getMetas if connection is InsightsConnection", async () => { + it("Should refreshAllgetMetas if connection is InsightsConnection", async () => { ext.connectedConnectionList.push(insightsConn); - await connectionManagerService.refreshGetMetas(); + await connectionManagerService.refreshAllGetMetas(); + sinon.assert.calledOnce(getMetaStub); + }); + it("Should not refreshGetMeta if connection is not InsightsConnection", async () => { + await connectionManagerService.refreshGetMeta("test"); + sinon.assert.notCalled(getMetaStub); + }); + + it("Should refreshGetMeta if connection is InsightsConnection", async () => { + ext.connectedConnectionList.push(insightsConn); + await connectionManagerService.refreshGetMeta(insightsConn.connLabel); sinon.assert.calledOnce(getMetaStub); }); }); From 98f2648a986f626c090a2e91abca3dc810803772 Mon Sep 17 00:00:00 2001 From: Philip Carneiro Date: Thu, 23 May 2024 11:25:58 +0100 Subject: [PATCH 10/12] remove form tests --- src/utils/core.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/utils/core.ts b/src/utils/core.ts index 3c7d738f..3f2866cb 100644 --- a/src/utils/core.ts +++ b/src/utils/core.ts @@ -250,6 +250,7 @@ export function getServerAlias(serverList: ServerDetails[]): void { }); } +/* istanbul ignore next */ export function offerConnectAction(connLabel: string): void { window .showInformationMessage( From 6c673c6646ed589d5b997820edc2262daf606a54 Mon Sep 17 00:00:00 2001 From: Philip Carneiro Date: Thu, 23 May 2024 11:55:47 +0100 Subject: [PATCH 11/12] add connect tests --- test/suite/commands.test.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/suite/commands.test.ts b/test/suite/commands.test.ts index fa310e8d..900b7cfe 100644 --- a/test/suite/commands.test.ts +++ b/test/suite/commands.test.ts @@ -1729,6 +1729,28 @@ describe("serverCommand", () => { assert.ok(updateServersStub.notCalled); }).timeout(5000); }); + + describe("connect", () => { + const connService = new ConnectionManagementService(); + const _console = vscode.window.createOutputChannel("q Console Output"); + const executionConsole = new ExecutionConsole(_console); + let windowErrorStub, retrieveConnectionStub: sinon.SinonStub; + + beforeEach(() => { + windowErrorStub = sinon.stub(vscode.window, "showErrorMessage"); + retrieveConnectionStub = sinon.stub(connService, "retrieveConnection"); + }); + + afterEach(() => { + sinon.restore(); + }); + + it("should show error message if connection not found", async () => { + retrieveConnectionStub.returns(undefined); + await serverCommand.connect("test"); + windowErrorStub.calledOnce; + }); + }); }); describe("walkthroughCommand", () => { From 4b55d889350d1f067ea6b759e09d176c8e720ea4 Mon Sep 17 00:00:00 2001 From: Philip Carneiro Date: Thu, 23 May 2024 11:56:03 +0100 Subject: [PATCH 12/12] add ignore --- src/services/dataSourceEditorProvider.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/services/dataSourceEditorProvider.ts b/src/services/dataSourceEditorProvider.ts index 126831fd..90caa2d8 100644 --- a/src/services/dataSourceEditorProvider.ts +++ b/src/services/dataSourceEditorProvider.ts @@ -135,6 +135,7 @@ export class DataSourceEditorProvider implements CustomTextEditorProvider { changeDocumentSubscription.dispose(); }); + /* istanbul ignore next */ webview.onDidReceiveMessage(async (msg: DataSourceMessage2) => { switch (msg.command) { case DataSourceCommand.Server: