visualproof 0.8.2 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -9
- package/dist/assets/tips/tour-library.webp +0 -0
- package/dist/assets/tips/tour-source.webp +0 -0
- package/dist/assets/tips/tour.json +90 -90
- package/dist/extractor/Extract.lean +34 -11
- package/dist/mcp/visualproof-mcp.mjs +30 -5
- package/dist/server/agent.js +19 -7
- package/dist/server/agententry.js +13 -6
- package/dist/server/agentexport.js +2 -1
- package/dist/server/agentfollow.js +13 -3
- package/dist/server/agentlean.js +91 -1
- package/dist/server/agentnotes.js +6 -4
- package/dist/server/agentread.js +33 -1
- package/dist/server/app.js +7 -3
- package/dist/server/appagent.js +1 -1
- package/dist/server/appgraph.js +24 -0
- package/dist/server/appshare.js +119 -1
- package/dist/server/apptalk.js +26 -0
- package/dist/server/boardspots.js +1 -1
- package/dist/server/children.js +6 -2
- package/dist/server/claudetokens.js +113 -0
- package/dist/server/doctor.js +7 -0
- package/dist/server/goals.js +224 -0
- package/dist/server/hosted.js +480 -0
- package/dist/server/hover.js +281 -8
- package/dist/server/live.js +34 -2
- package/dist/server/main.js +30 -2
- package/dist/server/mcptools.js +15 -7
- package/dist/server/options.js +30 -2
- package/dist/server/presence.js +2 -2
- package/dist/server/prompt.js +25 -0
- package/dist/server/readonlygate.js +2 -1
- package/dist/server/reviewapi.js +5 -2
- package/dist/server/status.js +43 -5
- package/dist/server/tokens.js +7 -4
- package/dist/shared/build.js +9 -0
- package/dist/shared/collab.js +17 -2
- package/dist/shared/declfind.js +23 -3
- package/dist/shared/goals.js +309 -0
- package/dist/shared/hygiene.js +18 -0
- package/dist/shared/noteplace.js +45 -19
- package/dist/shared/scope.js +74 -45
- package/dist/shared/sharesnap.js +4 -2
- package/dist/web/bundle/app.js +2368 -591
- package/dist/web/index.html +2 -1
- package/dist/web/src/highlight.js +53 -3
- package/dist/web/style.css +151 -0
- package/docs/agent-api/README.md +1 -1
- package/docs/agent-api/mcp.md +4 -2
- package/docs/agent-api/notes.md +3 -2
- package/docs/agent-api/reading.md +38 -2
- package/docs/agent-api/talking.md +7 -0
- package/docs/agent-api/words.md +3 -2
- package/package.json +1 -1
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
// The InfoView (ReviewSpec, "The InfoView"; the owner's decisions of 2026-11-01): what Lean's
|
|
2
|
+
// language server says of the goals at a place of a file — before the tactic there, and after it —
|
|
3
|
+
// and of the expected type of the term there, as the server gives it (server/hover.ts, read from
|
|
4
|
+
// Lean's answers by server/goals.ts) and the page draws it (web/src/infoview.ts). Nothing of it is
|
|
5
|
+
// precomputed: the usage pass elaborates without proofs, so only the language server, which
|
|
6
|
+
// elaborates the whole file, knows the goals.
|
|
7
|
+
//
|
|
8
|
+
// Lean is asked at positions alone. Which positions is read here from the text, as Lean would split
|
|
9
|
+
// a line into tactics: the tactic a place is in runs from just after the `by` or the separator
|
|
10
|
+
// before it (`;`, `<;>`, a case's `=>`, a focusing dot) to the separator after it, at the same depth
|
|
11
|
+
// of brackets. Lean's own rule (`goalsAt?`) gives the goals before a tactic at its first character
|
|
12
|
+
// and the goals after it from just past its first character to its end, so the goals before are
|
|
13
|
+
// asked at the tactic's first character and those after at its end. Where the text is read wrong
|
|
14
|
+
// the answer is still Lean's own at that place, as an editor would show it there.
|
|
15
|
+
//
|
|
16
|
+
// A tactic that holds a block of its own (`have h : P := by simp`) ends inside that block, where
|
|
17
|
+
// Lean has the nested proof's goals ("No goals"), not the outer proof's: the state after the whole
|
|
18
|
+
// line is the one the proof goes on from, the goals at the start of its next line of code (the
|
|
19
|
+
// owner's decision of 2026-11-01; afterLine). Where the proof does not go on, Lean's answer at the
|
|
20
|
+
// end.
|
|
21
|
+
export const CHANGES = ["wasChanged", "willChange", "wasInserted", "willInsert", "wasDeleted", "willDelete"];
|
|
22
|
+
/** A tagged text as plain text. */
|
|
23
|
+
export function flatten(t) {
|
|
24
|
+
if (typeof t === "string")
|
|
25
|
+
return t;
|
|
26
|
+
if (Array.isArray(t))
|
|
27
|
+
return t.map(flatten).join("");
|
|
28
|
+
return flatten(t.t);
|
|
29
|
+
}
|
|
30
|
+
/** The text of a goal as Lean writes it in its plain answer: the case, each hypothesis, the type. */
|
|
31
|
+
export function goalText(g) {
|
|
32
|
+
const hyps = g.hyps.map((h) => `${h.names.join(" ")} : ${flatten(h.type)}${h.val !== undefined ? ` := ${flatten(h.val)}` : ""}`);
|
|
33
|
+
return [...(g.case ? [`case ${g.case}`] : []), ...hyps, `${g.prefix ?? "⊢ "}${flatten(g.type)}`].join("\n");
|
|
34
|
+
}
|
|
35
|
+
const OPEN = "([{⟨⦃⟦";
|
|
36
|
+
const CLOSE = ")]}⟩⦄⟧";
|
|
37
|
+
/** One line's characters as the tactic reader sees them: the code's extent (comments and the
|
|
38
|
+
* spaces around it left out), the bracket depth before each character, and where the separators
|
|
39
|
+
* between tactics are. Strings and comments hold no brackets nor separators. */
|
|
40
|
+
function readLine(line) {
|
|
41
|
+
const depth = new Array(line.length + 1).fill(0);
|
|
42
|
+
const seps = [];
|
|
43
|
+
let end = line.length;
|
|
44
|
+
let d = 0;
|
|
45
|
+
let i = 0;
|
|
46
|
+
const word = /[\p{L}\p{N}_'!?.₀-₉ₐ-ₜ]/u;
|
|
47
|
+
while (i < line.length) {
|
|
48
|
+
const c = line[i];
|
|
49
|
+
depth[i] = d;
|
|
50
|
+
// a comment ends the line's code
|
|
51
|
+
if ((c === "-" && line[i + 1] === "-") || (c === "/" && line[i + 1] === "-")) {
|
|
52
|
+
if (c === "/") {
|
|
53
|
+
const close = line.indexOf("-/", i + 2);
|
|
54
|
+
if (close >= 0) {
|
|
55
|
+
// a comment closed on the line: what follows it is code
|
|
56
|
+
for (let j = i; j < close + 2; j++)
|
|
57
|
+
depth[j] = d;
|
|
58
|
+
i = close + 2;
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
end = i;
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
if (c === '"') {
|
|
66
|
+
let j = i + 1;
|
|
67
|
+
while (j < line.length && line[j] !== '"')
|
|
68
|
+
j += line[j] === "\\" ? 2 : 1;
|
|
69
|
+
for (let k = i; k <= Math.min(j, line.length - 1); k++)
|
|
70
|
+
depth[k] = d;
|
|
71
|
+
i = j + 1;
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if (word.test(c) && !(c === "." && !word.test(line[i + 1] ?? ""))) {
|
|
75
|
+
let j = i;
|
|
76
|
+
while (j < line.length && word.test(line[j]))
|
|
77
|
+
j++;
|
|
78
|
+
if (line.slice(i, j) === "by" && !word.test(line[i - 1] ?? ""))
|
|
79
|
+
seps.push({ at: i, len: 2, kind: "by" });
|
|
80
|
+
for (let k = i; k < j; k++)
|
|
81
|
+
depth[k] = d;
|
|
82
|
+
i = j;
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (OPEN.includes(c))
|
|
86
|
+
d++;
|
|
87
|
+
else if (CLOSE.includes(c))
|
|
88
|
+
d--;
|
|
89
|
+
else if (line.startsWith("<;>", i)) {
|
|
90
|
+
seps.push({ at: i, len: 3, kind: "sep" });
|
|
91
|
+
depth[i + 1] = depth[i + 2] = d;
|
|
92
|
+
i += 3;
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
else if (c === ";")
|
|
96
|
+
seps.push({ at: i, len: 1, kind: "sep" });
|
|
97
|
+
else if (c === "=" && line[i + 1] === ">") {
|
|
98
|
+
seps.push({ at: i, len: 2, kind: "arrow" });
|
|
99
|
+
depth[i + 1] = d;
|
|
100
|
+
i += 2;
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
else if (c === "|" && line[i + 1] !== "|" && line[i + 1] !== ">" && line[i - 1] !== "|" && line[i - 1] !== "<")
|
|
104
|
+
seps.push({ at: i, len: 1, kind: "bar" });
|
|
105
|
+
i++;
|
|
106
|
+
}
|
|
107
|
+
depth[line.length] = d;
|
|
108
|
+
while (end > 0 && /\s/.test(line[end - 1]))
|
|
109
|
+
end--;
|
|
110
|
+
let start = 0;
|
|
111
|
+
while (start < end && /\s/.test(line[start]))
|
|
112
|
+
start++;
|
|
113
|
+
return { start, end, depth, seps: seps.filter((s) => s.at < end) };
|
|
114
|
+
}
|
|
115
|
+
/** The tactic a place of a line is in, as Lean would split the line (above): its first character
|
|
116
|
+
* and the one past its last, focusing dots left out; null where the line holds no code. A place
|
|
117
|
+
* past the code's end (the caret after it, a comment) is in the line's last tactic. */
|
|
118
|
+
export function tacticSpan(line, ch) {
|
|
119
|
+
const { start, end, depth, seps } = readLine(line);
|
|
120
|
+
if (start >= end)
|
|
121
|
+
return null;
|
|
122
|
+
const at = Math.max(start, Math.min(ch, end - 1));
|
|
123
|
+
// the innermost `by` whose block holds the place: no bracket closes below its depth between them
|
|
124
|
+
let blockStart = start;
|
|
125
|
+
let D = depth[start];
|
|
126
|
+
for (const s of seps) {
|
|
127
|
+
if (s.kind !== "by" || s.at + s.len > at)
|
|
128
|
+
continue;
|
|
129
|
+
let inside = true;
|
|
130
|
+
for (let j = s.at; j < at; j++)
|
|
131
|
+
if (depth[j + 1] < depth[s.at])
|
|
132
|
+
inside = false;
|
|
133
|
+
if (inside && s.at + s.len >= blockStart) {
|
|
134
|
+
blockStart = s.at + s.len;
|
|
135
|
+
D = depth[s.at];
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
// its separators at the block's depth, read from its start: `;` and `<;>`; a match arm's `|` where
|
|
139
|
+
// arms are (after `with`, or another arm), not an absolute value's; and a `=>` that ends a case's
|
|
140
|
+
// head (`| succ n ih =>`, `case h =>`, `next =>`), not a `fun x =>`, whose body is a term. A `|`
|
|
141
|
+
// begins the head its `=>` ends, so the head is read from it
|
|
142
|
+
const cuts = [];
|
|
143
|
+
let last = blockStart;
|
|
144
|
+
let armed = false;
|
|
145
|
+
for (const s of seps) {
|
|
146
|
+
if (s.kind === "by" || s.at < blockStart || depth[s.at] !== D)
|
|
147
|
+
continue;
|
|
148
|
+
const before = line.slice(last, s.at).trim();
|
|
149
|
+
if (s.kind === "sep")
|
|
150
|
+
cuts.push({ at: s.at, past: s.at + s.len });
|
|
151
|
+
else if (s.kind === "bar") {
|
|
152
|
+
if (!(armed || before === "" || /(^|\s)with$/.test(before)))
|
|
153
|
+
continue;
|
|
154
|
+
armed = true;
|
|
155
|
+
cuts.push({ at: s.at, past: s.at });
|
|
156
|
+
}
|
|
157
|
+
else if (/^(\||case\b|next\b)/.test(before))
|
|
158
|
+
cuts.push({ at: s.at, past: s.at + s.len });
|
|
159
|
+
else
|
|
160
|
+
continue;
|
|
161
|
+
last = cuts[cuts.length - 1].past;
|
|
162
|
+
}
|
|
163
|
+
let from = blockStart;
|
|
164
|
+
let to = end;
|
|
165
|
+
for (const c of cuts) {
|
|
166
|
+
if (c.at < at && c.past <= at)
|
|
167
|
+
from = Math.max(from, c.past);
|
|
168
|
+
else if (c.at >= at) {
|
|
169
|
+
to = Math.min(to, c.at);
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
// a bracket that closes the block ends it
|
|
174
|
+
for (let j = at; j < to; j++)
|
|
175
|
+
if (CLOSE.includes(line[j]) && depth[j] <= D && depth[j + 1] < D) {
|
|
176
|
+
to = j;
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
// spaces, and the focusing dots at its head (`· simp`), are not the tactic
|
|
180
|
+
while (from < to && /[\s·.]/.test(line[from]) && !(line[from] === "." && /[\p{L}_]/u.test(line[from + 1] ?? "")))
|
|
181
|
+
from++;
|
|
182
|
+
while (to > from && /\s/.test(line[to - 1]))
|
|
183
|
+
to--;
|
|
184
|
+
if (from >= to)
|
|
185
|
+
return { from: Math.min(Math.max(start, at), end), to: Math.min(Math.max(start, at), end) };
|
|
186
|
+
return { from, to };
|
|
187
|
+
}
|
|
188
|
+
/** Whether the tactic `from`–`to` of a line holds a `by` of its own: a block nested in it
|
|
189
|
+
* (`have h : P := by simp`, `exact foo (by simp)`, a `by` that ends the line). */
|
|
190
|
+
export function holdsBy(line, from, to) {
|
|
191
|
+
return readLine(line).seps.some((s) => s.kind === "by" && s.at >= from && s.at < to);
|
|
192
|
+
}
|
|
193
|
+
/** Where the state after a tactic that holds a block of its own is (holdsBy): the start of the next
|
|
194
|
+
* line of code of the same proof after line `k` — the first whose code starts no further right than
|
|
195
|
+
* the tactic (`col`): a line further right is the nested block, or the tactic's term going on. Null
|
|
196
|
+
* past the text's end. Whether the proof goes on there is Lean's to say (no tactic state there: it
|
|
197
|
+
* does not). */
|
|
198
|
+
export function afterLine(text, k, col) {
|
|
199
|
+
const has = codeLines(text);
|
|
200
|
+
const lines = text.split("\n");
|
|
201
|
+
for (let j = k + 1; j < lines.length; j++) {
|
|
202
|
+
if (!has[j])
|
|
203
|
+
continue;
|
|
204
|
+
const ch = /^\s*/.exec(lines[j])[0].length;
|
|
205
|
+
if (ch <= col)
|
|
206
|
+
return { line: j, ch };
|
|
207
|
+
}
|
|
208
|
+
return null;
|
|
209
|
+
}
|
|
210
|
+
/** Whether each line of `text` holds code: something outside comments and docstrings, which spread
|
|
211
|
+
* over lines. */
|
|
212
|
+
export function codeLines(text) {
|
|
213
|
+
const lines = text.split("\n");
|
|
214
|
+
const out = lines.map(() => false);
|
|
215
|
+
let inComment = 0;
|
|
216
|
+
lines.forEach((l, k) => {
|
|
217
|
+
let i = 0;
|
|
218
|
+
while (i < l.length) {
|
|
219
|
+
if (inComment) {
|
|
220
|
+
if (l.startsWith("-/", i)) {
|
|
221
|
+
inComment--;
|
|
222
|
+
i += 2;
|
|
223
|
+
}
|
|
224
|
+
else if (l.startsWith("/-", i)) {
|
|
225
|
+
inComment++;
|
|
226
|
+
i += 2;
|
|
227
|
+
}
|
|
228
|
+
else
|
|
229
|
+
i++;
|
|
230
|
+
continue;
|
|
231
|
+
}
|
|
232
|
+
if (l.startsWith("/-", i)) {
|
|
233
|
+
inComment++;
|
|
234
|
+
i += 2;
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
if (l.startsWith("--", i))
|
|
238
|
+
break;
|
|
239
|
+
if (l[i] === '"') {
|
|
240
|
+
out[k] = true;
|
|
241
|
+
let j = i + 1;
|
|
242
|
+
while (j < l.length && l[j] !== '"')
|
|
243
|
+
j += l[j] === "\\" ? 2 : 1;
|
|
244
|
+
i = j + 1;
|
|
245
|
+
continue;
|
|
246
|
+
}
|
|
247
|
+
if (!/\s/.test(l[i]))
|
|
248
|
+
out[k] = true;
|
|
249
|
+
i++;
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
return out;
|
|
253
|
+
}
|
|
254
|
+
/** The next line of code after line `k` of `text` (`dir` 1), or before it (-1), and where its code
|
|
255
|
+
* starts: what ↑ and ↓ step to in the InfoView; null past the text's ends. */
|
|
256
|
+
export function stepLine(text, k, dir) {
|
|
257
|
+
const has = codeLines(text);
|
|
258
|
+
const lines = text.split("\n");
|
|
259
|
+
for (let j = k + dir; j >= 0 && j < lines.length; j += dir)
|
|
260
|
+
if (has[j])
|
|
261
|
+
return { line: j, ch: /^\s*/.exec(lines[j])[0].length };
|
|
262
|
+
return null;
|
|
263
|
+
}
|
|
264
|
+
/** One goal as Lean writes it in its plain answer (`$/lean/plainGoal`, `plainTermGoal`): an optional
|
|
265
|
+
* `case` line, hypotheses `a b : T` (or `x : T := v`), then `⊢ T` (`| T` in `conv`); what does not
|
|
266
|
+
* fit on a line goes on, indented, on the next. */
|
|
267
|
+
export function parsePlainGoal(s) {
|
|
268
|
+
const entries = [];
|
|
269
|
+
for (const l of s.split("\n")) {
|
|
270
|
+
if (entries.length && (/^\s/.test(l) || l === ""))
|
|
271
|
+
entries[entries.length - 1] += `\n${l}`;
|
|
272
|
+
else
|
|
273
|
+
entries.push(l);
|
|
274
|
+
}
|
|
275
|
+
const g = { hyps: [], type: "" };
|
|
276
|
+
for (const e of entries) {
|
|
277
|
+
if (!g.case && !g.hyps.length && e.startsWith("case "))
|
|
278
|
+
g.case = e.slice(5).trim();
|
|
279
|
+
else if (e.startsWith("⊢") || e.startsWith("| ")) {
|
|
280
|
+
const p = e.startsWith("⊢") ? (e.startsWith("⊢ ") ? "⊢ " : "⊢") : "| ";
|
|
281
|
+
g.prefix = p === "⊢" ? "⊢ " : p;
|
|
282
|
+
g.type = e.slice(p.length).replace(/^\n\s*/, "");
|
|
283
|
+
}
|
|
284
|
+
else {
|
|
285
|
+
const m = / :(?= |\n|$)/.exec(e);
|
|
286
|
+
if (!m)
|
|
287
|
+
continue;
|
|
288
|
+
const names = e.slice(0, m.index).split(/\s+/).filter(Boolean);
|
|
289
|
+
let type = e.slice(m.index + 2).replace(/^ |^\n\s*/, "");
|
|
290
|
+
let val;
|
|
291
|
+
// a `let`'s value, after a `:=` outside brackets
|
|
292
|
+
let depth = 0;
|
|
293
|
+
for (let i = 0; i < type.length; i++) {
|
|
294
|
+
const c = type[i];
|
|
295
|
+
if (OPEN.includes(c))
|
|
296
|
+
depth++;
|
|
297
|
+
else if (CLOSE.includes(c))
|
|
298
|
+
depth--;
|
|
299
|
+
else if (depth === 0 && type.startsWith(" := ", i)) {
|
|
300
|
+
val = type.slice(i + 4);
|
|
301
|
+
type = type.slice(0, i);
|
|
302
|
+
break;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
g.hyps.push({ names, type, ...(val !== undefined ? { val } : {}) });
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
return g;
|
|
309
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Names Lean's macro hygiene makes. A macro that writes a declaration under a name of its own, not one
|
|
2
|
+
// the reader wrote — Mathlib's `irreducible_def X` writes the value as `definition` and the opaque
|
|
3
|
+
// constant holding it as `wrapped` — has Lean add macro scopes to it, so that it clashes with nothing:
|
|
4
|
+
// `Fixture.definition._@.Fixture.Tagged._hyg.3` (with `._hygCtx` before `._hyg` on newer toolchains).
|
|
5
|
+
// The extractor folds such constants into the declaration the command writes (ViewNode.also). The
|
|
6
|
+
// page says them by what the macro wrote (`definition`, `wrapped`), and never asks Lean about one:
|
|
7
|
+
// what it names cannot be written in Lean source, so no `#check` or `#print` reaches it
|
|
8
|
+
// (server/hover.ts, `isDeclName`, refuses it).
|
|
9
|
+
/** Whether a name carries macro scopes: one Lean's hygiene made. */
|
|
10
|
+
export function hygienic(name) {
|
|
11
|
+
return name.includes("._@.");
|
|
12
|
+
}
|
|
13
|
+
/** A name without its macro scopes: what the macro wrote (`Fixture.definition`), as Lean's
|
|
14
|
+
* `Name.eraseMacroScopes` reads it; any other name as it is. */
|
|
15
|
+
export function withoutMacroScopes(name) {
|
|
16
|
+
const k = name.indexOf("._@.");
|
|
17
|
+
return k < 0 ? name : name.slice(0, k);
|
|
18
|
+
}
|
package/dist/shared/noteplace.js
CHANGED
|
@@ -35,10 +35,11 @@
|
|
|
35
35
|
// declaration wherever the board holds it — a reader's visitor counts — under every clustering,
|
|
36
36
|
// and a board that holds the declaration shows a note of the project attached to it (the derived
|
|
37
37
|
// clause of items). A board of a past build reads the declaration by its name in that build. Where
|
|
38
|
-
// the board's graph does not have the declaration (gone, with no rename carrying the note),
|
|
39
|
-
//
|
|
40
|
-
//
|
|
41
|
-
// where
|
|
38
|
+
// the board's graph does not have the declaration (gone, with no rename carrying the note), the note
|
|
39
|
+
// is on the ring, still attached, toward the cluster its place had it in (the owner's decision of
|
|
40
|
+
// 2026-10-30), shown on the boards its places show it on (decision 18), and at the declaration
|
|
41
|
+
// again should it come back; where the graph has it but the board does not, a note of the project
|
|
42
|
+
// shows only where it is linked or added, on the ring, and a view note where its place puts it.
|
|
42
43
|
//
|
|
43
44
|
// A key is never matched across clusterings: a namespace and a folder may share a key.
|
|
44
45
|
import { itemIn } from "./items.js";
|
|
@@ -271,18 +272,23 @@ export function itemsShownOn(notes, view, mode, nodes, full, links, nowName) {
|
|
|
271
272
|
}
|
|
272
273
|
/** Where project note `n` is on board `b`, which shows it (itemWhy): at the declaration it is
|
|
273
274
|
* attached to, where the board holds it (a visitor counts); attached to one the board's graph has
|
|
274
|
-
* but the board does not, on the ring, toward what it carries a file linked to on this board;
|
|
275
|
-
* attached to
|
|
276
|
-
*
|
|
277
|
-
*
|
|
278
|
-
*
|
|
279
|
-
*
|
|
275
|
+
* but the board does not, on the ring, toward what it carries a file linked to on this board;
|
|
276
|
+
* attached to one the graph does not have (gone), on the ring, toward the cluster its places had it
|
|
277
|
+
* in (placedAbout), else toward what it carries a file linked to; else, attached to none, in its
|
|
278
|
+
* cluster under the board's clustering where the board draws it; else on the ring — at the angle
|
|
279
|
+
* where it was let go, else toward what it carries a file linked to on this board (`linked`,
|
|
280
|
+
* linkedOn), else about its cluster under the other clustering where that holds a declaration of
|
|
281
|
+
* the board (decision 16), else in the order notes were written. */
|
|
280
282
|
export function itemSpot(n, b, exists, linked = []) {
|
|
281
283
|
const at = declOf(n, b, exists);
|
|
282
284
|
if (at && typeof at === "object")
|
|
283
285
|
return { at: "decl", j: at.j, name: at.name, d: [n.decl.at[0], n.decl.at[1]] };
|
|
284
286
|
if (at === "off")
|
|
285
287
|
return { at: "ring", angle: null, about: linked.length ? { links: [...linked] } : null };
|
|
288
|
+
// its declaration gone, no rename carrying it (the owner's decision of 2026-10-30): on the ring,
|
|
289
|
+
// still attached, where the declaration was rather than at a spot that now holds other things
|
|
290
|
+
if (at === "gone")
|
|
291
|
+
return { at: "ring", angle: null, about: placedAbout(n.places, b, exists) ?? (linked.length ? { links: [...linked] } : null), gone: n.decl.name };
|
|
286
292
|
const m = b.mode;
|
|
287
293
|
const place = n.places[m];
|
|
288
294
|
const h = holderOf(place, m, exists);
|
|
@@ -307,6 +313,22 @@ export function itemSpot(n, b, exists, linked = []) {
|
|
|
307
313
|
const about = linked.length ? { links: [...linked] } : o && b.on[otherMode(m)].has(o.key) ? { mode: otherMode(m), key: o.key } : null;
|
|
308
314
|
return { at: "ring", angle: place && "ring" in place ? place.ring : null, about };
|
|
309
315
|
}
|
|
316
|
+
/** What a note on the ring whose declaration is gone is about (the owner's decision of 2026-10-30):
|
|
317
|
+
* the cluster its place puts it in — the innermost of its keys that is still a cluster and holds a
|
|
318
|
+
* declaration of board `b` —, under the board's clustering, else under the other; null where none
|
|
319
|
+
* does. A note attached to a declaration has its places beside it (declPlace), so this is where the
|
|
320
|
+
* declaration was. */
|
|
321
|
+
export function placedAbout(places, b, exists) {
|
|
322
|
+
for (const m of [b.mode, otherMode(b.mode)]) {
|
|
323
|
+
const p = places[m];
|
|
324
|
+
if (!p || !("in" in p))
|
|
325
|
+
continue;
|
|
326
|
+
const key = p.in.map((e) => e[0]).find((k) => exists(m, k) && b.on[m].has(k));
|
|
327
|
+
if (key)
|
|
328
|
+
return { mode: m, key };
|
|
329
|
+
}
|
|
330
|
+
return null;
|
|
331
|
+
}
|
|
310
332
|
/** The declarations of board `b` a note on the ring is about, in the board's numbering: those of
|
|
311
333
|
* its cluster, or those its files are linked to — a declaration, or what a namespace or a folder
|
|
312
334
|
* holds on the board. */
|
|
@@ -330,21 +352,25 @@ export function aboutMembers(b, about) {
|
|
|
330
352
|
return [...out].sort((x, y) => x - y);
|
|
331
353
|
}
|
|
332
354
|
/** Where view note `n` is on its board `b`: at the declaration it is attached to, where the board
|
|
333
|
-
* holds it (a visitor counts), under every clustering;
|
|
334
|
-
*
|
|
335
|
-
*
|
|
336
|
-
|
|
337
|
-
|
|
355
|
+
* holds it (a visitor counts), under every clustering; attached to one the board's graph does not
|
|
356
|
+
* have (`exists`; unknown, it is taken to be there), on the ring about the innermost cluster of its
|
|
357
|
+
* place that holds a declaration of the board (the owner's decision of 2026-10-30); else under its
|
|
358
|
+
* own clustering as it always was, by the keys of the layout drawn (`index`); under the other, on
|
|
359
|
+
* the ring about that cluster. */
|
|
360
|
+
export function viewSpot(n, b, index, exists = NO_GRAPH) {
|
|
361
|
+
const at = declOf(n, b, exists);
|
|
338
362
|
if (at && typeof at === "object")
|
|
339
363
|
return { at: "decl", j: at.j, name: at.name, d: [n.decl.at[0], n.decl.at[1]] };
|
|
364
|
+
const key = n.place.in.map((e) => e[0]).find((k) => b.on[n.place.mode].has(k));
|
|
365
|
+
const about = key ? { mode: n.place.mode, key } : null;
|
|
366
|
+
if (at === "gone")
|
|
367
|
+
return { at: "ring", angle: null, about, gone: n.decl.name };
|
|
340
368
|
const r = resolvePlace(n.place, b.mode, index);
|
|
341
369
|
if (r)
|
|
342
370
|
return r.c >= 0 ? { at: "offset", c: r.c, d: [r.dx, r.dy] } : { at: "world", x: r.dx, y: r.dy };
|
|
343
|
-
|
|
344
|
-
return { at: "ring", angle: null, about: key ? { mode: n.place.mode, key } : null };
|
|
371
|
+
return { at: "ring", angle: null, about };
|
|
345
372
|
}
|
|
346
|
-
/** what a view note's attachment reads where the graph is not asked: off the board
|
|
347
|
-
* stands all the same */
|
|
373
|
+
/** what a view note's attachment reads where the graph is not asked: off the board, its place stands */
|
|
348
374
|
const NO_GRAPH = () => true;
|
|
349
375
|
/** The place under a layout's clustering of a note attached to declaration `i` of layout `L` (its
|
|
350
376
|
* numbering), as the layout has it: the declaration's own circle and every one around it, each with
|
package/dist/shared/scope.js
CHANGED
|
@@ -77,16 +77,18 @@ function stripComments(line, depth) {
|
|
|
77
77
|
}
|
|
78
78
|
return { text: out, depth };
|
|
79
79
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
80
|
+
const copyFrame = (f) => ({ ...f, opens: [...f.opens], aliases: new Map(f.aliases), open: [...f.open], variables: [...f.variables], universes: [...f.universes], options: [...f.options], local: [...f.local] });
|
|
81
|
+
/** A reading of a file from its start, line by line: `to(upto)` reads on up to line `upto`
|
|
82
|
+
* (0-based, the line a declaration's text starts on, never before a line asked for already) and
|
|
83
|
+
* says what is in force there, as reading the file from its start up to there says it. One reading
|
|
84
|
+
* says it at every declaration of a file, as File mode needs (web/src/filemode.ts): asked anew at
|
|
85
|
+
* each, a file of 3,000 lines was read 200 times over. */
|
|
86
|
+
function walker(lines, hasNamespace) {
|
|
87
|
+
const live = { stack: [frame("top", "", null, 0)], pending: null };
|
|
88
|
+
const current = (st) => st.stack.map((f) => f.ns).filter(Boolean).join(".");
|
|
87
89
|
/** What `open X` opens: X under the namespaces around it, innermost first, or X itself. */
|
|
88
|
-
const resolveNs = (x) => {
|
|
89
|
-
const cur = current().split(".").filter(Boolean);
|
|
90
|
+
const resolveNs = (st, x) => {
|
|
91
|
+
const cur = current(st).split(".").filter(Boolean);
|
|
90
92
|
const out = [];
|
|
91
93
|
for (let k = cur.length; k >= 0; k--) {
|
|
92
94
|
const n = [...cur.slice(0, k), x].join(".");
|
|
@@ -96,7 +98,7 @@ function walk(lines, upto, hasNamespace) {
|
|
|
96
98
|
return out;
|
|
97
99
|
};
|
|
98
100
|
/** `open …` (its arguments): what it opens, into a frame, and the command as written. */
|
|
99
|
-
const open = (args, cmd, into) => {
|
|
101
|
+
const open = (st, args, cmd, into) => {
|
|
100
102
|
const words = args.trim().split(/\s+/);
|
|
101
103
|
const scoped = words[0] === "scoped";
|
|
102
104
|
const spaces = [];
|
|
@@ -105,7 +107,7 @@ function walk(lines, upto, hasNamespace) {
|
|
|
105
107
|
const paren = /^([^\s(]+)\s*\(([^)]*)\)/.exec(rest.trim());
|
|
106
108
|
const renaming = /^([^\s]+)\s+renaming\s+(.*)$/.exec(rest.trim());
|
|
107
109
|
if (paren) {
|
|
108
|
-
for (const ns of resolveNs(paren[1])) {
|
|
110
|
+
for (const ns of resolveNs(st, paren[1])) {
|
|
109
111
|
spaces.push(ns);
|
|
110
112
|
if (!scoped)
|
|
111
113
|
for (const x of paren[2].trim().split(/\s+/))
|
|
@@ -114,7 +116,7 @@ function walk(lines, upto, hasNamespace) {
|
|
|
114
116
|
}
|
|
115
117
|
}
|
|
116
118
|
else if (renaming) {
|
|
117
|
-
for (const ns of resolveNs(renaming[1])) {
|
|
119
|
+
for (const ns of resolveNs(st, renaming[1])) {
|
|
118
120
|
spaces.push(ns);
|
|
119
121
|
if (!scoped)
|
|
120
122
|
for (const pair of renaming[2].split(",")) {
|
|
@@ -129,7 +131,7 @@ function walk(lines, upto, hasNamespace) {
|
|
|
129
131
|
for (const w of (hiding >= 0 ? rest.slice(0, hiding) : rest).trim().split(/\s+/)) {
|
|
130
132
|
if (!w)
|
|
131
133
|
continue;
|
|
132
|
-
const ns = resolveNs(w);
|
|
134
|
+
const ns = resolveNs(st, w);
|
|
133
135
|
spaces.push(...ns);
|
|
134
136
|
// scoped opens bring notation and instances, no names
|
|
135
137
|
if (!scoped)
|
|
@@ -139,11 +141,12 @@ function walk(lines, upto, hasNamespace) {
|
|
|
139
141
|
into.open.push({ ...cmd, namespaces: [...new Set(spaces)], ...(scoped ? { scoped: true } : {}) });
|
|
140
142
|
};
|
|
141
143
|
/** What a whole command does, once all its lines are read. */
|
|
142
|
-
const finish = (text, line) => {
|
|
144
|
+
const finish = (st, text, line) => {
|
|
145
|
+
const stack = st.stack;
|
|
143
146
|
let m;
|
|
144
147
|
if ((m = NAMESPACE.exec(text))) {
|
|
145
148
|
stack.push(frame("namespace", m[1], m[1], line));
|
|
146
|
-
pending = null;
|
|
149
|
+
st.pending = null;
|
|
147
150
|
return;
|
|
148
151
|
}
|
|
149
152
|
if ((m = SECTION.exec(text))) {
|
|
@@ -151,12 +154,12 @@ function walk(lines, upto, hasNamespace) {
|
|
|
151
154
|
if (/\bnoncomputable\s+section\b/.test(text))
|
|
152
155
|
f.noncomputable = true;
|
|
153
156
|
stack.push(f);
|
|
154
|
-
pending = null;
|
|
157
|
+
st.pending = null;
|
|
155
158
|
return;
|
|
156
159
|
}
|
|
157
160
|
if (MUTUAL.test(text)) {
|
|
158
161
|
stack.push(frame("mutual", "", null, line));
|
|
159
|
-
pending = null;
|
|
162
|
+
st.pending = null;
|
|
160
163
|
return;
|
|
161
164
|
}
|
|
162
165
|
if ((m = END.exec(text))) {
|
|
@@ -164,7 +167,7 @@ function walk(lines, upto, hasNamespace) {
|
|
|
164
167
|
let parts = m[1] ? m[1].split(".").length : 1;
|
|
165
168
|
while (parts > 0 && stack.length > 1)
|
|
166
169
|
parts -= (stack.pop().name ?? "_").split(".").length;
|
|
167
|
-
pending = null;
|
|
170
|
+
st.pending = null;
|
|
168
171
|
return;
|
|
169
172
|
}
|
|
170
173
|
if (ATTRIBUTES.test(text))
|
|
@@ -172,18 +175,18 @@ function walk(lines, upto, hasNamespace) {
|
|
|
172
175
|
const head = IN_HEAD.test(text);
|
|
173
176
|
// `open A in def x …` on one line holds for that command alone, which is not the one asked about
|
|
174
177
|
if (head && !VARIABLE.test(text) && /\sin\s/.test(text)) {
|
|
175
|
-
pending = null;
|
|
178
|
+
st.pending = null;
|
|
176
179
|
return;
|
|
177
180
|
}
|
|
178
181
|
const onlyNext = head && IN.test(text);
|
|
179
182
|
const body = onlyNext ? text.replace(IN, "") : text;
|
|
180
183
|
// a command that is not `… in` uses up what was pending: a declaration, or anything else
|
|
181
|
-
const into = onlyNext ? (pending ??= frame("top", "", null, line)) : stack[stack.length - 1];
|
|
184
|
+
const into = onlyNext ? (st.pending ??= frame("top", "", null, line)) : stack[stack.length - 1];
|
|
182
185
|
if (!onlyNext)
|
|
183
|
-
pending = null;
|
|
186
|
+
st.pending = null;
|
|
184
187
|
const cmd = (t) => ({ line: line + 1, text: t, ...(onlyNext ? { in: true } : {}) });
|
|
185
188
|
if ((m = OPEN.exec(body)))
|
|
186
|
-
open(m[1], cmd(body), into);
|
|
189
|
+
open(st, m[1], cmd(body), into);
|
|
187
190
|
else if ((m = VARIABLE.exec(body)))
|
|
188
191
|
into.variables.push(cmd(m[1]));
|
|
189
192
|
else if ((m = UNIVERSE.exec(body)))
|
|
@@ -196,31 +199,42 @@ function walk(lines, upto, hasNamespace) {
|
|
|
196
199
|
let depth = 0;
|
|
197
200
|
/** the command being read: its first line, and its text so far */
|
|
198
201
|
let reading = null;
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
202
|
+
let l = 0;
|
|
203
|
+
return {
|
|
204
|
+
to(upto) {
|
|
205
|
+
for (; l < upto && l < lines.length; l++) {
|
|
206
|
+
const line = lines[l];
|
|
207
|
+
const inComment = depth > 0;
|
|
208
|
+
const s = stripComments(line, depth);
|
|
209
|
+
depth = s.depth;
|
|
210
|
+
const text = s.text.replace(/\s+/g, " ").trim();
|
|
211
|
+
if (!text)
|
|
212
|
+
continue;
|
|
213
|
+
// a command starts at the line's first column, outside a comment; anything else continues it
|
|
214
|
+
if (!inComment && !/^\s/.test(line)) {
|
|
215
|
+
if (reading)
|
|
216
|
+
finish(live, reading.text, reading.line);
|
|
217
|
+
reading = { line: l, text };
|
|
218
|
+
}
|
|
219
|
+
else if (reading)
|
|
220
|
+
reading.text += " " + text;
|
|
221
|
+
}
|
|
222
|
+
// the command read last ends where the reading stops: finished on a copy, the reading going
|
|
223
|
+
// on from here with it still open
|
|
224
|
+
const st = { stack: live.stack.map(copyFrame), pending: live.pending && copyFrame(live.pending) };
|
|
209
225
|
if (reading)
|
|
210
|
-
finish(reading.text, reading.line);
|
|
211
|
-
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
reading.text += " " + text;
|
|
215
|
-
}
|
|
216
|
-
if (reading)
|
|
217
|
-
finish(reading.text, reading.line);
|
|
218
|
-
return { stack, pending };
|
|
226
|
+
finish(st, reading.text, reading.line);
|
|
227
|
+
return st;
|
|
228
|
+
},
|
|
229
|
+
};
|
|
219
230
|
}
|
|
220
|
-
/**
|
|
221
|
-
*
|
|
222
|
-
|
|
223
|
-
|
|
231
|
+
/** Read a file up to line `upto` (0-based, the line a declaration's text starts on): the frames in
|
|
232
|
+
* force there, and the commands written `… in` right before it. */
|
|
233
|
+
function walk(lines, upto, hasNamespace) {
|
|
234
|
+
return walker(lines, hasNamespace).to(upto);
|
|
235
|
+
}
|
|
236
|
+
/** A Scope from what is in force at a line. */
|
|
237
|
+
function scopeOf({ stack, pending }) {
|
|
224
238
|
const frames = pending ? [...stack, pending] : stack;
|
|
225
239
|
const cur = stack.map((f) => f.ns).filter(Boolean).join(".").split(".").filter(Boolean);
|
|
226
240
|
const namespaces = [];
|
|
@@ -232,6 +246,21 @@ export function scopeAt(lines, upto, hasNamespace) {
|
|
|
232
246
|
aliases.set(k, v);
|
|
233
247
|
return { namespaces, opens: [...new Set(frames.flatMap((f) => f.opens))], aliases };
|
|
234
248
|
}
|
|
249
|
+
/** The scope at each of lines `uptos` of a file (in any order), as `scopeAt` says it at each, from
|
|
250
|
+
* one reading of the file. */
|
|
251
|
+
export function scopesAt(lines, uptos, hasNamespace) {
|
|
252
|
+
const w = walker(lines, hasNamespace);
|
|
253
|
+
const out = new Array(uptos.length);
|
|
254
|
+
const order = uptos.map((_, k) => k).sort((a, b) => uptos[a] - uptos[b]);
|
|
255
|
+
for (const k of order)
|
|
256
|
+
out[k] = scopeOf(w.to(uptos[k]));
|
|
257
|
+
return out;
|
|
258
|
+
}
|
|
259
|
+
/** The scope at line `upto` of a file (the line a declaration's text starts on): what a short name
|
|
260
|
+
* written there can mean. */
|
|
261
|
+
export function scopeAt(lines, upto, hasNamespace) {
|
|
262
|
+
return scopeOf(walk(lines, upto, hasNamespace));
|
|
263
|
+
}
|
|
235
264
|
/** Everything in force at line `upto` of a file, as written: the context a declaration there is
|
|
236
265
|
* read in. */
|
|
237
266
|
export function contextAt(lines, upto, hasNamespace) {
|