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; }