feat(xugu): expose object type members in schema tree

This commit is contained in:
Elias authored and GitHub committed 2026-08-11 02:12:22 +08:00
1 parent d7e93453c7
commit 1b37e97486
30 files changed
+1364 -63

No files matched your search

@@ -156,7 +156,7 @@ export function canTreeNodeExpand(type: TreeNodeType): boolean {
}
export function canTreeNodeShowExpander({ type, childCount, explicitContainer = false }: { type: TreeNodeType; childCount?: number; explicitContainer?: boolean }): boolean {
if (!canTreeNodeExpand(type) && !(type === "package" && explicitContainer)) return false;
if (!canTreeNodeExpand(type) && !((type === "package" || type === "type") && explicitContainer)) return false;
if (childCount === 0 && emptyContainerTypes.has(type)) return false;
return true;
}
@@ -92,7 +92,7 @@ export function treeNodeRowAction(type: TreeNodeType, canExpand: boolean, activa
if (!shouldActivateTreeNodeOnSingleClick(type, activation)) return "none";
if (type === "extension") return "open-extension-details";
if (dataNodeTypes.has(type)) return "open-data";
if (type === "package" && canExpand) return "toggle";
if ((type === "package" || type === "type") && canExpand) return "toggle";
if (sourceNodeTypes.has(type)) return "open-source";
if (toggleLeafNodeTypes.has(type)) return "toggle";
if (canExpand) return "toggle";
@@ -0,0 +1,57 @@
import type { CompletionAssistantCandidate, TreeNode } from "@/types/database";
export function isXuguTypeMemberContainer(node: TreeNode, databaseType?: string): boolean {
return databaseType === "xugu" && node.type === "type" && node.xuguTypeMembersExpandable === true && !!node.connectionId && !!node.database;
}
export function buildXuguTypeMemberNodes(typeNode: TreeNode, candidates: readonly CompletionAssistantCandidate[]): TreeNode[] {
const parentName = typeNode.objectName || typeNode.label;
const parentSchema = typeNode.schema;
const seen = new Set<string>();
const attributes: TreeNode[] = [];
const methods: TreeNode[] = [];
for (const candidate of candidates) {
const name = candidate.name.trim();
if (!name || (candidate.kind !== "column" && candidate.kind !== "procedure" && candidate.kind !== "function")) continue;
const signature = candidate.signature?.trim() || "";
const dataType = candidate.data_type?.trim() || "";
const key = `${candidate.kind}\0${name}\0${signature}\0${dataType}`;
if (seen.has(key)) continue;
seen.add(key);
const base = {
connectionId: typeNode.connectionId,
database: typeNode.database,
schema: parentSchema,
parentName,
parentSchema,
parentType: "type" as const,
isExpanded: false,
children: undefined,
};
if (candidate.kind === "column") {
attributes.push({
...base,
id: `${typeNode.id}:attribute:${name}`,
label: dataType ? `${name} (${dataType})` : name,
type: "type-attribute",
objectName: name,
});
continue;
}
const call = `${name}(${signature})`;
const label = candidate.kind === "function" ? `FUNCTION ${call}${dataType ? ` → ${dataType}` : ""}` : `PROCEDURE ${call}`;
methods.push({
...base,
id: `${typeNode.id}:method:${candidate.kind}:${name}:${signature}`,
label,
type: "type-method",
objectName: name,
signature: signature || undefined,
});
}
return [...attributes, ...methods];
}