* The focal symbol's members, in source order, one level of nesting deep. * * A file's outline is file → class → method, so direct children alone would * show a class and nothing inside it. The grandchildren come from ONE batched * `getOutgoingEdgesFrom` over the container children, never a quer
( cg: CodeGraph, focal: Node, containsOut: readonly Edge[], endpoints: Map<string, Node>, overrides?: Map<string, WireOverride> )
| 238 | * `getOutgoingEdgesFrom` over the container children, never a query per child. |
| 239 | */ |
| 240 | function buildMembers( |
| 241 | cg: CodeGraph, |
| 242 | focal: Node, |
| 243 | containsOut: readonly Edge[], |
| 244 | endpoints: Map<string, Node>, |
| 245 | overrides?: Map<string, WireOverride> |
| 246 | ): { items: WireMember[]; total: number } { |
| 247 | // Each member once, and never the symbol itself or a file: a component in a |
| 248 | // Vue / Svelte / Astro file was recorded as containing its script's file node |
| 249 | // and every symbol in it, so the walk one level down met those symbols |
| 250 | // again — and a member listed twice is a repeated key the viewer cannot draw. |
| 251 | const seen = new Set<string>([focal.id]); |
| 252 | const admit = (child: Node | undefined): child is Node => |
| 253 | !!child && child.kind !== 'file' && !seen.has(child.id) && !!seen.add(child.id); |
| 254 | const direct: Array<{ node: Node; parentId: string; depth: number }> = []; |
| 255 | for (const edge of containsOut) { |
| 256 | const child = endpoints.get(edge.target); |
| 257 | if (admit(child)) direct.push({ node: child, parentId: focal.id, depth: 1 }); |
| 258 | } |
| 259 | |
| 260 | const containerIds = direct |
| 261 | .filter((entry) => CONTAINER_KINDS.has(entry.node.kind)) |
| 262 | .map((entry) => entry.node.id); |
| 263 | |
| 264 | const nested: Array<{ node: Node; parentId: string; depth: number }> = []; |
| 265 | if (containerIds.length > 0) { |
| 266 | const grandEdges = cg.getOutgoingEdgesFrom(containerIds, ['contains']); |
| 267 | const grandNodes = cg.getNodesByIds(grandEdges.map((e) => e.target)); |
| 268 | for (const edge of grandEdges) { |
| 269 | const child = grandNodes.get(edge.target); |
| 270 | if (admit(child)) nested.push({ node: child, parentId: edge.source, depth: 2 }); |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | const all = [...direct, ...nested].sort( |
| 275 | (a, b) => a.node.startLine - b.node.startLine || a.node.name.localeCompare(b.node.name) |
| 276 | ); |
| 277 | const shown = all.slice(0, MAX_OUTLINE_NODES); |
| 278 | |
| 279 | // Two queries for the whole outline, not two per row: a file with 400 |
| 280 | // symbols would otherwise be 800 lookups behind one screen. |
| 281 | const memberIds = shown.map((entry) => entry.node.id); |
| 282 | const fanIn = cg.getFanIn(memberIds); |
| 283 | const fanOut = cg.getFanOut(memberIds); |
| 284 | |
| 285 | return { |
| 286 | items: shown.map((entry) => { |
| 287 | const member: WireMember = { |
| 288 | ...toNodeRef(entry.node), |
| 289 | parentId: entry.parentId, |
| 290 | depth: entry.depth, |
| 291 | fanIn: fanIn.get(entry.node.id) ?? 0, |
| 292 | fanOut: fanOut.get(entry.node.id) ?? 0, |
| 293 | }; |
| 294 | const override = overrides?.get(entry.node.id); |
| 295 | if (override) member.overrides = override; |
| 296 | return member; |
| 297 | }), |