MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / buildMap

Function buildMap

src/ui-server/api/map.ts:583–772  ·  view source on GitHub ↗
(cg: CodeGraph, projectRoot: string, query: URLSearchParams)

Source from the content-addressed store, hash-verified

581}
582
583export 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) {

Callers 1

handlerFunction · 0.90

Calls 15

isTestFileFunction · 0.90
wireListFunction · 0.90
parseMapQueryFunction · 0.85
passThroughDirsFunction · 0.85
pickDefaultViewFunction · 0.85
pickDefaultDepthFunction · 0.85
moduleIdForFunction · 0.85
collapseLoneRootFilesFunction · 0.85
countDependentsFunction · 0.85
rootOptionsFunction · 0.85
fileCyclesFunction · 0.85
mapMethod · 0.80

Tested by

no test coverage detected