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

Function moduleIdFor

src/ui-server/api/map.ts:300–332  ·  view source on GitHub ↗
(
  filePath: string,
  root: string,
  depth: number,
  passThrough?: ReadonlySet<string>
)

Source from the content-addressed store, hash-verified

298 * keeps its own box, everything else joins the `(root files)` bucket.
299 */
300export function moduleIdFor(
301 filePath: string,
302 root: string,
303 depth: number,
304 passThrough?: ReadonlySet<string>
305): { id: string; facade: boolean; label: string } | null {
306 const path = toPosixPath(filePath);
307 let rel = path;
308 if (root) {
309 if (!path.startsWith(`${root}/`)) return null;
310 rel = path.slice(root.length + 1);
311 }
312 const parts = rel.split('/').filter(Boolean);
313 if (parts.length === 0) return null;
314 const dirs = parts.slice(0, -1);
315 const ends = levelEnds(root, dirs, passThrough);
316 if (ends.length < depth) {
317 // A loose file. The directories it DOES have still qualify it, so
318 // `src/a/b.ts` at depth 2 lands in `src/a/(root files)`, not the top one.
319 const dir = joinPath(root, dirs);
320 const dirLabel = levelLabel(root, dirs, ends);
321 const file = parts[parts.length - 1] ?? '';
322 if (FACADE_STEMS.has(stemOf(file))) {
323 return { id: joinPath(root, parts), facade: true, label: dirLabel ? `${dirLabel}/${file}` : file };
324 }
325 return { id: rootFilesId(dir), facade: false, label: rootFilesId(dirLabel) };
326 }
327 return {
328 id: joinPath(root, dirs.slice(0, ends[depth - 1])),
329 facade: false,
330 label: levelLabel(root, dirs, ends.slice(0, depth)),
331 };
332}
333
334/**
335 * The root the map opens on: the directory holding the most non-test symbols.

Callers 3

ui-map-api.test.tsFile · 0.90
tallyModulesFunction · 0.85
buildMapFunction · 0.85

Calls 6

levelEndsFunction · 0.85
levelLabelFunction · 0.85
rootFilesIdFunction · 0.85
hasMethod · 0.80
joinPathFunction · 0.70
stemOfFunction · 0.70

Tested by

no test coverage detected