export function buildGraphEdgeId(edge) {
    return `${edge.source}->${edge.target}:${edge.kind}`;
}
export function buildGraphEdgeIndex(edges) {
    const edgeIndex = new Map();
    for (const edge of edges) {
        const sourceEdges = edgeIndex.get(edge.source);
        if (sourceEdges) {
            sourceEdges.push(edge);
        }
        else {
            edgeIndex.set(edge.source, [edge]);
        }
        const targetEdges = edgeIndex.get(edge.target);
        if (targetEdges) {
            targetEdges.push(edge);
        }
        else {
            edgeIndex.set(edge.target, [edge]);
        }
    }
    return edgeIndex;
}
export function buildFileFocusedSelection({ filePath, fileIndex, edgeIndex, }) {
    const fileSymbolIds = fileIndex.get(filePath) || [];
    const nodeIds = new Set();
    const edges = new Map();
    for (const symbolId of fileSymbolIds) {
        nodeIds.add(symbolId);
        for (const edge of edgeIndex.get(symbolId) || []) {
            nodeIds.add(edge.source);
            nodeIds.add(edge.target);
            edges.set(buildGraphEdgeId(edge), edge);
        }
    }
    return {
        nodeIds: [...nodeIds],
        edges: [...edges.values()],
    };
}
