Lines 3–20 at 318 (were 3–13 at 175)
33// two ways: in the agent's own view (what its folder shows), and in shared's 44// numbering (the shared lines it changes, or the shared line its new lines 55// follow), so agents can compare where they are against one common text. 6−import type { AtomId, LineId } from "../../src/engine/index.ts";
6+import { type AtomId, type LineId, type ReadView, seqOf } from "../../src/engine/index.ts"; 77import type { Project } from "./project.ts"; 99type Range = [number, number]; 11+/** A view's reads by line number (View has them; another ReadView may not). */ 12+type ByNumber = ReadView & { 13+ fileOfNumber?(n: number): string; 14+ lineNumberOf?(path: string, n: number): number; 15+ visibleWriters?(path: string): readonly number[]; 1118function ranges(ns: number[]): Range[] { 1219 const out: Range[] = []; 1320 for (const n of [...new Set(ns)].sort((a, b) => a - b)) { Lines 37–54 at 318 (were 30–40 at 175)
3138export function where(project: Project) { 3239 const graph = project.graph; 33− let shared: ReturnType<Project["sharedView"]> | undefined;
34− const sharedNumber = (file: string, id: LineId): number | undefined => {
35− shared ??= project.sharedView();
40+ let shared: ByNumber | undefined; 41+ // By the file's index of visible lines (abso Capacity): finding it in lines() built every line of the file again 42+ // whenever the file changed, per line asked. 43+ const sharedNumber = (file: string, line: LineId | number): number | undefined => { 44+ shared ??= project.sharedView() as ByNumber; 3645 if (!shared.hasFile(file)) return undefined; 37− const i = shared.lines(file).findIndex((l) => l.id === id);
47+ typeof line === "string" 48+ ? shared.lineNumber(file, line) 49+ : shared.lineNumberOf 50+ ? shared.lineNumberOf(file, line) 51+ : shared.lineNumber(file, graph.lineIdOf(line)); 3852 return i >= 0 ? i + 1 : undefined; 4054 const files: Record<string, Spot[]> = {}; Lines 56–65 at 318 (were 42–47 at 175)
4256 const draft = project.draftOf(agent); 4357 if (!draft || draft.atoms.length === 0) continue; 4458 const mine = new Set<AtomId>(draft.atoms); 59+ // Once per agent (abso Capacity): each read of draft.view asks the project's view cache, which weighs every 61+ const view = draft.view as ByNumber; 62+ const fileOfNumber = view.fileOfNumber?.bind(view); 4563 const perFile = new Map<string, { view: number[]; shared: number[]; changes: Set<AtomId>; last: number }>(); 4664 const at = (file: string) => { 4765 let s = perFile.get(file); Lines 70–76 at 318 (were 52–58 at 175)
5270 const atom = graph.atom(id); 5371 for (const run of atom.inserts) { 5472 // A line moved by someone (#28) is in the file the draft's view puts it in. 55− const file = run.parent.startsWith("^") ? run.file : draft.view.fileOf(run.parent);
73+ const file = run.parent.startsWith("^") ? run.file : view.fileOf(run.parent); 5876 s.last = Math.max(s.last, atom.time); Lines 78–100 at 318 (were 60–69 at 175)
6078 const anchor = run.parent.startsWith("^") ? 0 : sharedNumber(file, run.parent); 6179 if (anchor !== undefined) s.shared.push(Math.max(anchor, 1)); 81+ // By number where the view can (abso Capacity): a draft deleting a big generated file read every line's text 82+ // to check it exists, and looked up each line's id. 84+ for (const line of graph.deletedNumbers(id)) { 85+ const file = fileOfNumber(line); 88+ s.last = Math.max(s.last, atom.time); 89+ const n = sharedNumber(file, line); 90+ if (n !== undefined) s.shared.push(n); 6394 for (const lineId of atom.deletes) { 6495 const info = graph.line(lineId); 6596 if (!info) continue; 66− const file = draft.view.fileOf(lineId);
97+ const file = view.fileOf(lineId); 69100 s.last = Math.max(s.last, atom.time); Lines 103–118 at 318 (were 72–81 at 175)
74105 for (const [file, s] of perFile) { 75− if (draft.view.hasFile(file)) {
76− draft.view.lines(file).forEach((l, i) => {
77− if (mine.has(l.atom)) s.view.push(i + 1);
78− });
106+ if (view.hasFile(file)) { 107+ if (view.visibleWriters) { 108+ const seqs = new Set(draft.atoms.map(seqOf)); 109+ view.visibleWriters(file).forEach((seq, i) => { 110+ if (seqs.has(seq)) s.view.push(i + 1); 113+ view.lines(file).forEach((l, i) => { 114+ if (mine.has(l.atom)) s.view.push(i + 1); 80117 (files[file] ??= []).push({