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

Function rootOptions

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

* The roots the selector offers: the repository root plus every top-level * directory that holds indexed files, biggest first. * * A monorepo's answer to "which project am I looking at" — and on a single * project it is a one-line list nobody has to use.

(
  files: ReadonlyArray<{ path: string; symbols: number }>
)

Source from the content-addressed store, hash-verified

839 * project it is a one-line list nobody has to use.
840 */
841function rootOptions(
842 files: ReadonlyArray<{ path: string; symbols: number }>
843): WireMapPayload['roots'] {
844 const byDir = new Map<string, number>();
845 for (const file of files) {
846 const slash = file.path.indexOf('/');
847 if (slash <= 0) continue;
848 const dir = file.path.slice(0, slash);
849 byDir.set(dir, (byDir.get(dir) ?? 0) + 1);
850 }
851 const dirs = [...byDir]
852 .sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]))
853 .map(([root, count]) => ({ root, label: root, files: count }));
854 return [{ root: '', label: 'whole repository', files: files.length }, ...dirs];
855}

Callers 1

buildMapFunction · 0.85

Calls 3

mapMethod · 0.80
getMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected