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

Function scopesOf

src/ui-server/api/program.ts:223–228  ·  view source on GitHub ↗

* The constructs a site is written inside, outermost first: its guards and its * loops merged by where each one STARTS. Both were read by the same climb up * the same ancestors, and on one ancestor chain an outer construct always * begins before an inner one — so the positions alone rebuild the n

(site: ProgramSite)

Source from the content-addressed store, hash-verified

221 * without either reading having to know about the other.
222 */
223function scopesOf(site: ProgramSite): Scope[] {
224 const guards: Scope[] = site.guards.map((guard) => ({ kind: 'guard' as const, branch: guard.branch, guard }));
225 const loops: Scope[] = (site.loops ?? []).map((loop) => ({ kind: 'loop' as const, branch: loop.branch, loop }));
226 if (loops.length === 0) return guards;
227 return [...guards, ...loops].sort((a, b) => at(a.branch) - at(b.branch) || a.branch.localeCompare(b.branch));
228}
229
230/** A `line:column` branch as one number, for ordering constructs by where they start. */
231function at(branch: string): number {

Callers 1

blockForFunction · 0.85

Calls 2

mapMethod · 0.80
atFunction · 0.70

Tested by

no test coverage detected