diff --git a/src/extensionVariables.ts b/src/extensionVariables.ts index 12ef415b..2c1bbb55 100644 --- a/src/extensionVariables.ts +++ b/src/extensionVariables.ts @@ -134,6 +134,7 @@ export namespace ext { "Tables", "Variables", "Views", + "Namespaces", ]; export const qNamespaceFilters = [".q", ".Q", ".h", ".z", ".o", ".j", ".m"]; diff --git a/src/models/serverObject.ts b/src/models/serverObject.ts index d8858fdc..b4a7b133 100644 --- a/src/models/serverObject.ts +++ b/src/models/serverObject.ts @@ -25,13 +25,13 @@ export interface ServerObject { isNs: boolean; } -export async function loadNamespaces(): Promise { +export async function loadNamespaces(root?: string): Promise { const serverObjects = await loadServerObjects(); if (serverObjects !== undefined) { const ns = serverObjects.filter((value) => { return value.isNs ? value : undefined; }); - return ns; + return getNamespaces(ns, root); } return new Array(); } @@ -101,3 +101,20 @@ export async function loadViews(): Promise { }); return views ?? new Array(); } + +function getNamespaces(input: ServerObject[], root = "."): ServerObject[] { + const output: ServerObject[] = []; + + input.forEach((v, i) => { + let index = -1; + if (root === v.namespace) { + index = i; + } + + if (index != -1) { + output.push(v); + } + }); + + return output; +} diff --git a/src/services/kdbTreeProvider.ts b/src/services/kdbTreeProvider.ts index 45bb9d62..edc8a8cf 100644 --- a/src/services/kdbTreeProvider.ts +++ b/src/services/kdbTreeProvider.ts @@ -140,7 +140,9 @@ export class KdbTreeProvider implements TreeDataProvider { return result; } - private async getServerObjects(serverType: TreeItem): Promise { + private async getServerObjects( + serverType: TreeItem + ): Promise { if (serverType === undefined) return new Array(); const ns = serverType.contextValue ?? ""; if (serverType.label === ext.qObjectCategories[0]) { @@ -204,7 +206,7 @@ export class KdbTreeProvider implements TreeDataProvider { (x) => new QServerNode( [], - `${ns === "." ? "" : ns + "."}${x.name}`, + `${ns === "." ? "." : ""}${x.name}`, "", TreeItemCollapsibleState.None, "p-var" @@ -233,6 +235,18 @@ export class KdbTreeProvider implements TreeDataProvider { } else { return new Array(); } + } else if (serverType.label === ext.qObjectCategories[5]) { + // nested namespaces + const namespaces = await loadNamespaces(ns); + const result = namespaces.map( + (x) => + new QNamespaceNode([], x.name, "", TreeItemCollapsibleState.Collapsed) + ); + if (result !== undefined) { + return result; + } else { + return Array(); + } } return new Array(); }