From ebefab2a29a7539a5bc3701fe8325df18f6023ab Mon Sep 17 00:00:00 2001 From: Philip Carneiro Date: Thu, 25 Apr 2024 09:49:56 +0100 Subject: [PATCH 1/3] fix disconnect bug --- src/services/connectionManagerService.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/services/connectionManagerService.ts b/src/services/connectionManagerService.ts index 34d3e582..cfa9611c 100644 --- a/src/services/connectionManagerService.ts +++ b/src/services/connectionManagerService.ts @@ -29,6 +29,7 @@ import { } from "../utils/core"; import { Insights } from "../models/insights"; import { Server } from "../models/server"; +import { refreshDataSourcesPanel } from "../utils/dataSource"; export class ConnectionManagementService { public retrieveConnection( @@ -116,6 +117,7 @@ export class ConnectionManagementService { } else { this.isNotConnectedBehaviour(connLabel); } + refreshDataSourcesPanel(); } } @@ -240,6 +242,15 @@ export class ConnectionManagementService { ext.connectedConnectionList.indexOf(connection), 1, ); + ext.connectedContextStrings.splice( + ext.connectedContextStrings.indexOf(connection.connLabel), + 1, + ); + commands.executeCommand( + "setContext", + "kdb.connected", + ext.connectedContextStrings, + ); if (ext.activeConnection === connection) { ext.activeConnection = undefined; ext.connectionNode = undefined; From 87243ccc82f968bf5491d857d87a79139eac74b4 Mon Sep 17 00:00:00 2001 From: Philip Carneiro Date: Thu, 25 Apr 2024 10:08:02 +0100 Subject: [PATCH 2/3] fix small ux bug --- package.json | 8 ++++---- src/services/connectionManagerService.ts | 14 +------------- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index 51bdc4e5..bfae0cdd 100644 --- a/package.json +++ b/package.json @@ -559,22 +559,22 @@ { "command": "kdb.insightsConnect", "when": "view == kdb-servers && viewItem not in kdb.connected && viewItem in kdb.insightsNodes", - "group": "connection" + "group": "connection@0" }, { "command": "kdb.insightsRemove", "when": "view == kdb-servers && viewItem in kdb.insightsNodes", - "group": "connection" + "group": "connection@5" }, { "command": "kdb.disconnect", "when": "view == kdb-servers && viewItem in kdb.connected && (viewItem in kdb.rootNodes || viewItem in kdb.insightsNodes)", - "group": "connection" + "group": "connection@4" }, { "command": "kdb.removeConnection", "when": "view == kdb-servers && viewItem in kdb.rootNodes", - "group": "connection@2" + "group": "connection@5" }, { "command": "kdb.startLocalProcess", diff --git a/src/services/connectionManagerService.ts b/src/services/connectionManagerService.ts index cfa9611c..074c5723 100644 --- a/src/services/connectionManagerService.ts +++ b/src/services/connectionManagerService.ts @@ -144,19 +144,7 @@ export class ConnectionManagementService { /* istanbul ignore next */ if (isLocal && connectionNode) { connection.getConnection()?.close(() => { - ext.connectedConnectionList.splice( - ext.connectedConnectionList.indexOf(connection), - 1, - ); - ext.activeConnection = undefined; - ext.connectionNode = undefined; - - commands.executeCommand("setContext", "kdb.connected.active", false); - Telemetry.sendEvent("Connection.Disconnected"); - ext.outputChannel.appendLine( - `Connection stopped from ${connection.connLabel}`, - ); - ext.serverProvider.reload(); + this.disconnectBehaviour(connection); }); } else { connection.disconnect(); From 0c238ab4d7a49b6a5037e784976b8f2b6b681cb1 Mon Sep 17 00:00:00 2001 From: Philip Carneiro Date: Thu, 25 Apr 2024 11:08:18 +0100 Subject: [PATCH 3/3] fix ds --- src/commands/serverCommand.ts | 1 - src/services/connectionManagerService.ts | 5 +++++ src/services/dataSourceTreeProvider.ts | 14 +++++++------- src/utils/dataSource.ts | 24 ++++++++++-------------- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/commands/serverCommand.ts b/src/commands/serverCommand.ts index f3eb876a..9243988b 100644 --- a/src/commands/serverCommand.ts +++ b/src/commands/serverCommand.ts @@ -273,7 +273,6 @@ export async function removeConnection(viewItem: KdbNode | InsightsNode) { export async function connect(viewItem: KdbNode | InsightsNode): Promise { const connMngService = new ConnectionManagementService(); commands.executeCommand("kdb-results.focus"); - await commands.executeCommand("setContext", "kdb.insightsConnected", false); ExecutionConsole.start(); // handle cleaning up existing connection if (ext.activeConnection !== undefined) { diff --git a/src/services/connectionManagerService.ts b/src/services/connectionManagerService.ts index 074c5723..7c14cb09 100644 --- a/src/services/connectionManagerService.ts +++ b/src/services/connectionManagerService.ts @@ -131,6 +131,11 @@ export class ConnectionManagementService { ]); Telemetry.sendEvent("Connection.Connected.Active"); ext.activeConnection = connection; + if (node instanceof InsightsNode) { + commands.executeCommand("setContext", "kdb.insightsConnected", true); + } else { + commands.executeCommand("setContext", "kdb.insightsConnected", false); + } ext.serverProvider.reload(); } diff --git a/src/services/dataSourceTreeProvider.ts b/src/services/dataSourceTreeProvider.ts index 44c696d0..66b65bee 100644 --- a/src/services/dataSourceTreeProvider.ts +++ b/src/services/dataSourceTreeProvider.ts @@ -46,7 +46,7 @@ export class KdbDataSourceProvider implements TreeDataProvider { this.refresh(); const datasourceFolder = createKdbDataSourcesFolder(); this.watcher = workspace.createFileSystemWatcher( - new RelativePattern(datasourceFolder, ext.kdbDataSourceFileGlob) + new RelativePattern(datasourceFolder, ext.kdbDataSourceFileGlob), ); // watch updates in the folder this.watcher.onDidChange(() => this.refresh()); @@ -59,7 +59,7 @@ export class KdbDataSourceProvider implements TreeDataProvider { } getChildren( - element?: KdbDataSourceTreeItem + element?: KdbDataSourceTreeItem, ): Promise { if (!element) { return this.getDsFiles(); @@ -84,7 +84,7 @@ export class KdbDataSourceProvider implements TreeDataProvider { const files = fs.readdirSync(kdbDataSourcesFolderPath); const dsFiles = files.filter((file) => { const isFromInsightsNode = checkFileFromInsightsNode( - path.join(kdbDataSourcesFolderPath, file) + path.join(kdbDataSourcesFolderPath, file), ); return ( path.extname(file) === ext.kdbDataSourceFileExtension && @@ -97,9 +97,9 @@ export class KdbDataSourceProvider implements TreeDataProvider { return new KdbDataSourceTreeItem( newLabel, TreeItemCollapsibleState.None, - [Uri.file(path.join(kdbDataSourcesFolderPath, file))] + [Uri.file(path.join(kdbDataSourcesFolderPath, file))], ); - }) + }), ); } else { return Promise.resolve([]); @@ -111,7 +111,7 @@ export class KdbDataSourceTreeItem extends TreeItem { constructor( public readonly label: string, public readonly collapsibleState: TreeItemCollapsibleState, - public readonly files: Uri[] + public readonly files: Uri[], ) { super(label, collapsibleState); this.iconPath = new ThemeIcon("file"); @@ -125,7 +125,7 @@ export class KdbDataSourceTreeItem extends TreeItem { commands.executeCommand( "setContext", "kdb.dataSourceTreeNodes", - ext.kdbDataSourceRootNodes + ext.kdbDataSourceRootNodes, ); } } diff --git a/src/utils/dataSource.ts b/src/utils/dataSource.ts index afcdea63..d2501aff 100644 --- a/src/utils/dataSource.ts +++ b/src/utils/dataSource.ts @@ -16,19 +16,20 @@ import path from "path"; import { ext } from "../extensionVariables"; import { DataSourceFiles } from "../models/dataSource"; import { DataSourcesPanel } from "../panels/datasource"; +import { InsightsConnection } from "../classes/insightsConnection"; export function createKdbDataSourcesFolder(): string { const rootPath = ext.context.globalStorageUri.fsPath; const kdbDataSourcesFolderPath = path.join(rootPath, ext.kdbDataSourceFolder); if (!fs.existsSync(rootPath)) { ext.outputChannel.appendLine( - `Directory created to the extension folder: ${rootPath}` + `Directory created to the extension folder: ${rootPath}`, ); fs.mkdirSync(rootPath); } if (!fs.existsSync(kdbDataSourcesFolderPath)) { ext.outputChannel.appendLine( - `Directory created to the extension folder: ${kdbDataSourcesFolderPath}` + `Directory created to the extension folder: ${kdbDataSourcesFolderPath}`, ); fs.mkdirSync(kdbDataSourcesFolderPath); } @@ -45,21 +46,16 @@ export function convertTimeToTimestamp(time: string): string { return `${datePart}.${timePart}`; } catch (error) { console.error( - `The string param is in an incorrect format. Param: ${time} Error: ${error}` + `The string param is in an incorrect format. Param: ${time} Error: ${error}`, ); return ""; } } export function getConnectedInsightsNode(): string { - const connectedNode = ext.kdbinsightsNodes.find((node) => - node.endsWith(" (connected)") - ); - if (connectedNode) { - return connectedNode.replace(" (connected)", ""); - } else { - return ""; - } + return ext.activeConnection instanceof InsightsConnection + ? ext.activeConnection.connLabel + : ""; } export function checkFileFromInsightsNode(filePath: string): boolean { @@ -78,7 +74,7 @@ export function checkFileFromInsightsNode(filePath: string): boolean { export function checkIfTimeParamIsCorrect( startTS: string, - endTS: string + endTS: string, ): boolean { try { const startDate = new Date(startTS); @@ -86,7 +82,7 @@ export function checkIfTimeParamIsCorrect( return startDate < endDate; } catch (error) { console.error( - `The string params are in an incorrect format. startTS: ${startTS}, endTS: ${endTS}, Error: ${error}` + `The string params are in an incorrect format. startTS: ${startTS}, endTS: ${endTS}, Error: ${error}`, ); return false; } @@ -99,7 +95,7 @@ export function refreshDataSourcesPanel(): void { } export function convertDataSourceFormToDataSourceFile( - form: any + form: any, ): DataSourceFiles { return form as DataSourceFiles; }