(cg: CodeGraph, projectRoot: string, query: URLSearchParams)
| 581 | } |
| 582 | |
| 583 | export function buildMap(cg: CodeGraph, projectRoot: string, query: URLSearchParams): WireMapPayload { |
| 584 | const started = Date.now(); |
| 585 | const { root: requestedRoot, depth: requestedDepth } = parseMapQuery(query); |
| 586 | |
| 587 | const fileRecords = cg.getFiles().map((file) => { |
| 588 | const path = toPosixPath(file.path); |
| 589 | return { |
| 590 | path, |
| 591 | language: file.language, |
| 592 | symbols: file.nodeCount ?? 0, |
| 593 | test: isTestFile(path), |
| 594 | generated: file.generated === true, |
| 595 | }; |
| 596 | }); |
| 597 | |
| 598 | const passThrough = passThroughDirs(fileRecords.map((f) => f.path)); |
| 599 | // Root first, then depth against THAT root: how finely to cut depends on |
| 600 | // what is being cut. Choosing `src` and then asking for one level under it |
| 601 | // is the same question as choosing the whole project and asking for two. |
| 602 | const view = requestedRoot === null ? pickDefaultView(fileRecords, passThrough) : null; |
| 603 | const root = view?.root ?? requestedRoot ?? ''; |
| 604 | const depth = requestedDepth ?? view?.depth ?? pickDefaultDepth(fileRecords, root, passThrough); |
| 605 | const stats = cg.getStats(); |
| 606 | const key = [ |
| 607 | projectRoot, |
| 608 | cg.getLastIndexedAt() ?? 0, |
| 609 | stats.edgeCount, |
| 610 | stats.fileCount, |
| 611 | root, |
| 612 | depth, |
| 613 | ].join('\u0000'); |
| 614 | const hit = cache.get(key); |
| 615 | if (hit) { |
| 616 | // Re-stamp rather than mutate: the cached body is shared, and a caller |
| 617 | // must not see another request's elapsed time. |
| 618 | return { ...hit, timing: { elapsedMs: Date.now() - started, cached: true } }; |
| 619 | } |
| 620 | |
| 621 | const assignments: Array<{ filePath: string; module: string }> = []; |
| 622 | const modules = new Map< |
| 623 | string, |
| 624 | { |
| 625 | id: string; |
| 626 | facade: boolean; |
| 627 | files: number; |
| 628 | symbols: number; |
| 629 | testFiles: number; |
| 630 | generatedFiles: number; |
| 631 | generatedPaths: Set<string>; |
| 632 | languages: Map<Language, number>; |
| 633 | paths: string[]; |
| 634 | } |
| 635 | >(); |
| 636 | const moduleOfFile = new Map<string, string>(); |
| 637 | |
| 638 | const assigned = new Map<string, { id: string; facade: boolean; label: string }>(); |
| 639 | const labelOf = new Map<string, string>(); |
| 640 | for (const file of fileRecords) { |
no test coverage detected