* Extract code blocks for key nodes in the subgraph
(
subgraph: Subgraph,
maxBlocks: number,
maxBlockSize: number
)
| 1462 | * Extract code blocks for key nodes in the subgraph |
| 1463 | */ |
| 1464 | private async extractCodeBlocks( |
| 1465 | subgraph: Subgraph, |
| 1466 | maxBlocks: number, |
| 1467 | maxBlockSize: number |
| 1468 | ): Promise<CodeBlock[]> { |
| 1469 | const blocks: CodeBlock[] = []; |
| 1470 | |
| 1471 | // Prioritize entry points, then functions/methods |
| 1472 | const priorityNodes: Node[] = []; |
| 1473 | |
| 1474 | // First: entry points |
| 1475 | for (const id of subgraph.roots) { |
| 1476 | const node = subgraph.nodes.get(id); |
| 1477 | if (node) { |
| 1478 | priorityNodes.push(node); |
| 1479 | } |
| 1480 | } |
| 1481 | |
| 1482 | // Then: functions and methods |
| 1483 | for (const node of subgraph.nodes.values()) { |
| 1484 | if (!subgraph.roots.includes(node.id)) { |
| 1485 | if (node.kind === 'function' || node.kind === 'method') { |
| 1486 | priorityNodes.push(node); |
| 1487 | } |
| 1488 | } |
| 1489 | } |
| 1490 | |
| 1491 | // Then: classes |
| 1492 | for (const node of subgraph.nodes.values()) { |
| 1493 | if (!subgraph.roots.includes(node.id)) { |
| 1494 | if (node.kind === 'class') { |
| 1495 | priorityNodes.push(node); |
| 1496 | } |
| 1497 | } |
| 1498 | } |
| 1499 | |
| 1500 | // Extract code for priority nodes |
| 1501 | for (const node of priorityNodes) { |
| 1502 | if (blocks.length >= maxBlocks) break; |
| 1503 | |
| 1504 | const code = await this.extractNodeCode(node); |
| 1505 | if (code) { |
| 1506 | // Truncate if too long. Language-neutral marker (no `//` — not a |
| 1507 | // comment in Python, Ruby, etc.); this renders inside a fenced |
| 1508 | // source block whose language varies. |
| 1509 | const truncated = code.length > maxBlockSize |
| 1510 | ? code.slice(0, maxBlockSize) + '\n... (truncated) ...' |
| 1511 | : code; |
| 1512 | |
| 1513 | blocks.push({ |
| 1514 | content: truncated, |
| 1515 | filePath: node.filePath, |
| 1516 | startLine: node.startLine, |
| 1517 | endLine: node.endLine, |
| 1518 | language: node.language, |
| 1519 | node, |
| 1520 | }); |
| 1521 | } |
no test coverage detected