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

Function collapseLoneRootFiles

src/ui-server/api/map.ts:560–581  ·  view source on GitHub ↗

* Rename `x/(root files)` to `x` wherever the bucket is all `x` has. * * The bucket earns its name only when it stands beside something: `src` holding * both `src/api` and three loose files needs a box for the loose ones, and that * box has to say it is not the whole of `src`. But a `backend/con

(ids: ReadonlySet<string>)

Source from the content-addressed store, hash-verified

558 * Returns only the ids that move, so a caller can leave the rest alone.
559 */
560function collapseLoneRootFiles(ids: ReadonlySet<string>): Map<string, string> {
561 const renamed = new Map<string, string>();
562 for (const id of ids) {
563 const cut = id.lastIndexOf('/(root files)');
564 // A bucket at the very top (`(root files)`) has no directory to become.
565 if (cut <= 0 || cut + '/(root files)'.length !== id.length) continue;
566 const dir = id.slice(0, cut);
567 let alone = true;
568 for (const other of ids) {
569 // A façade counts: `src/utils` beside `src/utils/index.tsx` would read as
570 // if the box contained the file drawn next to it.
571 if (other !== id && other.startsWith(`${dir}/`)) {
572 alone = false;
573 break;
574 }
575 }
576 // `dir` can only already be a module if something lives BELOW it, which is
577 // exactly the case `alone` just ruled out — so this rename cannot collide.
578 if (alone) renamed.set(id, dir);
579 }
580 return renamed;
581}
582
583export function buildMap(cg: CodeGraph, projectRoot: string, query: URLSearchParams): WireMapPayload {
584 const started = Date.now();

Callers 1

buildMapFunction · 0.85

Calls 1

setMethod · 0.45

Tested by

no test coverage detected