@tsplc/tmp-debug 0.0.0-stage → 0.6.3
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 +38 -2
- package/dist/api.js +744 -0
- package/dist/api.js.map +12 -0
- package/dist/constant.js +33 -0
- package/dist/constant.js.map +10 -0
- package/dist/explain-file.js +468 -0
- package/dist/explain-file.js.map +11 -0
- package/dist/explain.js +1310 -0
- package/dist/explain.js.map +19 -0
- package/dist/format.js +214 -0
- package/dist/format.js.map +12 -0
- package/dist/index.js +4066 -0
- package/dist/index.js.map +44 -0
- package/dist/manifest.js +240 -0
- package/dist/manifest.js.map +10 -0
- package/dist/paths.js +242 -0
- package/dist/paths.js.map +10 -0
- package/package.json +72 -4
- package/src/adapter.ts +77 -0
- package/src/api.ts +446 -0
- package/src/app-server.ts +151 -0
- package/src/build-files.ts +46 -0
- package/src/constant.ts +41 -0
- package/src/debugger.ts +237 -0
- package/src/errors.ts +13 -0
- package/src/explain-expressions.ts +484 -0
- package/src/explain-file.ts +325 -0
- package/src/explain-frames.ts +155 -0
- package/src/explain-loops.ts +151 -0
- package/src/explain-operations.ts +232 -0
- package/src/explain-tables.ts +345 -0
- package/src/explain-value.ts +203 -0
- package/src/explain-verdicts.ts +548 -0
- package/src/explain.ts +82 -0
- package/src/hardware.ts +159 -0
- package/src/http.ts +218 -0
- package/src/index.ts +44 -0
- package/src/jobs.ts +139 -0
- package/src/login-value.ts +165 -0
- package/src/login.ts +315 -0
- package/src/manifest.ts +328 -0
- package/src/opcua.ts +80 -0
- package/src/paths.ts +363 -0
- package/src/requests.ts +99 -0
- package/src/server-cursor.ts +22 -0
- package/src/shown.ts +229 -0
- package/src/telemetry.ts +125 -0
- package/src/timeline.ts +148 -0
- package/src/trace.ts +62 -0
- package/src/ui/bits.ts +48 -0
- package/src/ui/client.ts +87 -0
- package/src/ui/dom.ts +61 -0
- package/src/ui/explain-read.ts +105 -0
- package/src/ui/format.ts +261 -0
- package/src/ui/hardware.ts +425 -0
- package/src/ui/header.ts +207 -0
- package/src/ui/health.ts +64 -0
- package/src/ui/index.ts +27 -0
- package/src/ui/jobs.ts +263 -0
- package/src/ui/links.ts +59 -0
- package/src/ui/live-value.ts +85 -0
- package/src/ui/main.ts +76 -0
- package/src/ui/overview.ts +178 -0
- package/src/ui/page.ts +286 -0
- package/src/ui/pages.ts +64 -0
- package/src/ui/recent-window.ts +49 -0
- package/src/ui/recent.ts +355 -0
- package/src/ui/request-trace.ts +38 -0
- package/src/ui/requests.ts +80 -0
- package/src/ui/routes.ts +98 -0
- package/src/ui/store.ts +295 -0
- package/src/ui/success-cache.ts +11 -0
- package/src/ui/tree.ts +162 -0
- package/src/ui/variables.ts +597 -0
- package/src/ui/why-watch.ts +11 -0
- package/src/ui/why.ts +694 -0
- package/src/values.ts +170 -0
- package/src/watch.ts +32 -0
package/src/ui/header.ts
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { h } from "./dom";
|
|
2
|
+
import {
|
|
3
|
+
formatAge,
|
|
4
|
+
formatClock,
|
|
5
|
+
formatElapsed,
|
|
6
|
+
formatTimeOfDay,
|
|
7
|
+
readingLabel,
|
|
8
|
+
} from "./format";
|
|
9
|
+
import { href, ROUTES, type Route } from "./routes";
|
|
10
|
+
import type { Store, Topic } from "./store";
|
|
11
|
+
|
|
12
|
+
interface Notice {
|
|
13
|
+
tone: "danger" | "warn" | "error";
|
|
14
|
+
text: string;
|
|
15
|
+
dismiss?: VoidFunction;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const shortId = (id: string | null) =>
|
|
19
|
+
id === null ? "unknown" : id.slice(0, 10);
|
|
20
|
+
|
|
21
|
+
const readout = (label: string, ...value: (Node | string)[]) =>
|
|
22
|
+
h(
|
|
23
|
+
"div",
|
|
24
|
+
{ class: "readout" },
|
|
25
|
+
h("span", { class: "label" }, label),
|
|
26
|
+
h("span", { class: "reading" }, ...value),
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
/** Always visible: which build runs, how values are read and whether they can be, and how far to trust times. */
|
|
30
|
+
export const header = (store: Store) => {
|
|
31
|
+
const readouts = h("div", { class: "readouts" });
|
|
32
|
+
const banners = h("div", { class: "banners" });
|
|
33
|
+
const links = new Map(
|
|
34
|
+
ROUTES.map((route) => [route, h("a", { href: href({ route }) }, route)]),
|
|
35
|
+
);
|
|
36
|
+
const element = h(
|
|
37
|
+
"header",
|
|
38
|
+
{},
|
|
39
|
+
h(
|
|
40
|
+
"div",
|
|
41
|
+
{ class: "bar" },
|
|
42
|
+
h(
|
|
43
|
+
"div",
|
|
44
|
+
{ class: "brand" },
|
|
45
|
+
h("b", {}, "tsPLC"),
|
|
46
|
+
h("span", {}, "debug"),
|
|
47
|
+
h(
|
|
48
|
+
"span",
|
|
49
|
+
{ class: "ro", title: "The debugger never writes or forces values" },
|
|
50
|
+
"read-only",
|
|
51
|
+
),
|
|
52
|
+
),
|
|
53
|
+
readouts,
|
|
54
|
+
),
|
|
55
|
+
h("nav", {}, ...links.values()),
|
|
56
|
+
banners,
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
const render = () => {
|
|
60
|
+
const { session } = store;
|
|
61
|
+
const { build, connection, reading } = session;
|
|
62
|
+
const buildState = build.matches ? "match" : "mismatch";
|
|
63
|
+
readouts.replaceChildren(
|
|
64
|
+
readout(
|
|
65
|
+
"build",
|
|
66
|
+
h(
|
|
67
|
+
"span",
|
|
68
|
+
{
|
|
69
|
+
class: `build ${buildState}`,
|
|
70
|
+
title: `manifest ${build.manifest ?? "none"}\ncontroller ${build.controller ?? "unknown"}`,
|
|
71
|
+
},
|
|
72
|
+
`manifest ${shortId(build.manifest)}`,
|
|
73
|
+
h("i", {}, build.matches ? " = " : " ≠ "),
|
|
74
|
+
`controller ${shortId(build.controller)}`,
|
|
75
|
+
),
|
|
76
|
+
),
|
|
77
|
+
readout(
|
|
78
|
+
"values",
|
|
79
|
+
h("span", {
|
|
80
|
+
class: `dot c-${connection.state}`,
|
|
81
|
+
title: connection.endpoint,
|
|
82
|
+
}),
|
|
83
|
+
readingLabel(reading),
|
|
84
|
+
h(
|
|
85
|
+
"span",
|
|
86
|
+
{ class: "dim" },
|
|
87
|
+
` · ${connection.state} since ${formatTimeOfDay(connection.since)}`,
|
|
88
|
+
` (${formatElapsed(store.ageOf(connection.since))})`,
|
|
89
|
+
),
|
|
90
|
+
),
|
|
91
|
+
// The PLC clock counts from the runtime's start, so only the precision of the mapping means anything.
|
|
92
|
+
readout(
|
|
93
|
+
"plc clock",
|
|
94
|
+
session.clock
|
|
95
|
+
? `±${session.clock.uncertaintyMs.toFixed(1)} ms against the app server's`
|
|
96
|
+
: "not estimated",
|
|
97
|
+
),
|
|
98
|
+
readout(
|
|
99
|
+
"scans",
|
|
100
|
+
...session.tasks.map((task) => {
|
|
101
|
+
const interval = store.manifest.tasks.find(
|
|
102
|
+
(candidate) => candidate.name === task.name,
|
|
103
|
+
)?.intervalMs;
|
|
104
|
+
return h(
|
|
105
|
+
"span",
|
|
106
|
+
{
|
|
107
|
+
class: "task",
|
|
108
|
+
title:
|
|
109
|
+
interval === undefined
|
|
110
|
+
? task.name
|
|
111
|
+
: `${task.name}: configured every ${interval} ms`,
|
|
112
|
+
},
|
|
113
|
+
`${task.name} `,
|
|
114
|
+
h(
|
|
115
|
+
"b",
|
|
116
|
+
{},
|
|
117
|
+
task.scansPerSecond === null
|
|
118
|
+
? "—"
|
|
119
|
+
: task.scansPerSecond.toFixed(1),
|
|
120
|
+
),
|
|
121
|
+
"/s",
|
|
122
|
+
task.dropped > 0
|
|
123
|
+
? h(
|
|
124
|
+
"span",
|
|
125
|
+
{
|
|
126
|
+
class: "err",
|
|
127
|
+
title:
|
|
128
|
+
"Telemetry records overwritten before the PLC sent them: Recent is missing these",
|
|
129
|
+
},
|
|
130
|
+
` ${task.dropped} dropped`,
|
|
131
|
+
)
|
|
132
|
+
: "",
|
|
133
|
+
);
|
|
134
|
+
}),
|
|
135
|
+
),
|
|
136
|
+
readout(
|
|
137
|
+
"release",
|
|
138
|
+
session.release
|
|
139
|
+
? h(
|
|
140
|
+
"span",
|
|
141
|
+
{ title: `deployed ${session.release.deployedAt}` },
|
|
142
|
+
`${session.release.id} · ${session.release.operation} · ${formatAge(store.ageOf(session.release.deployedAt))}`,
|
|
143
|
+
)
|
|
144
|
+
: "not reported",
|
|
145
|
+
),
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
const notices: Notice[] = [];
|
|
149
|
+
if (!build.matches) {
|
|
150
|
+
notices.push({
|
|
151
|
+
tone: "danger",
|
|
152
|
+
text:
|
|
153
|
+
build.controller === null
|
|
154
|
+
? "The controller's build id could not be read, so this manifest may not describe what is running."
|
|
155
|
+
: `Build mismatch: the controller runs ${build.controller}, but this manifest is ${build.manifest ?? "missing"}. Paths, values and source links may be wrong.`,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
if (store.stream === "reconnecting") {
|
|
159
|
+
notices.push({
|
|
160
|
+
tone: "warn",
|
|
161
|
+
text: "Lost the stream from the debugger host; reconnecting. Every value is stale until it resumes.",
|
|
162
|
+
});
|
|
163
|
+
} else if (connection.state !== "connected") {
|
|
164
|
+
notices.push({
|
|
165
|
+
tone: "warn",
|
|
166
|
+
text: `${connection.error ?? `Reading values: ${connection.state} since ${formatClock(connection.since)}.`} Values shown are the last read and marked stale.`,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
if (store.error) {
|
|
170
|
+
notices.push({
|
|
171
|
+
tone: "error",
|
|
172
|
+
text: store.error,
|
|
173
|
+
dismiss: () => store.clearError(),
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
banners.replaceChildren(
|
|
177
|
+
...notices.map(({ tone, text, dismiss }) =>
|
|
178
|
+
h(
|
|
179
|
+
"div",
|
|
180
|
+
{ class: `banner ${tone}` },
|
|
181
|
+
text,
|
|
182
|
+
dismiss ? h("button", { onclick: dismiss }, "dismiss") : "",
|
|
183
|
+
),
|
|
184
|
+
),
|
|
185
|
+
);
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
render();
|
|
189
|
+
return {
|
|
190
|
+
element,
|
|
191
|
+
update(topics: Set<Topic>) {
|
|
192
|
+
if (
|
|
193
|
+
topics.has("session") ||
|
|
194
|
+
topics.has("stream") ||
|
|
195
|
+
topics.has("error") ||
|
|
196
|
+
topics.has("clock")
|
|
197
|
+
) {
|
|
198
|
+
render();
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
setRoute(route: Route) {
|
|
202
|
+
for (const [name, link] of links) {
|
|
203
|
+
link.classList.toggle("on", name === route);
|
|
204
|
+
}
|
|
205
|
+
},
|
|
206
|
+
};
|
|
207
|
+
};
|
package/src/ui/health.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { HealthState } from "../api";
|
|
2
|
+
import type { DebugDevice } from "../manifest";
|
|
3
|
+
import { h } from "./dom";
|
|
4
|
+
import type { Store } from "./store";
|
|
5
|
+
|
|
6
|
+
interface HealthView {
|
|
7
|
+
health: HealthState;
|
|
8
|
+
text: string;
|
|
9
|
+
detail: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* A device's health as far as its driver reported it: "unknown" without a health target, "needs
|
|
14
|
+
* login" while nothing can read it, never "OK" by default.
|
|
15
|
+
*/
|
|
16
|
+
export const deviceHealth = (store: Store, device: DebugDevice): HealthView => {
|
|
17
|
+
const state = store.devices.get(device.id);
|
|
18
|
+
const { connection } = store.session;
|
|
19
|
+
if (!device.health) {
|
|
20
|
+
return {
|
|
21
|
+
health: "unknown",
|
|
22
|
+
text: "unknown",
|
|
23
|
+
detail: "This build reads no health for this device",
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
if (connection.state === "unavailable") {
|
|
27
|
+
return {
|
|
28
|
+
health: "unknown",
|
|
29
|
+
text: "needs login",
|
|
30
|
+
detail: connection.error ?? "",
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
if (!state || state.health.state === "unknown") {
|
|
34
|
+
return {
|
|
35
|
+
health: "unknown",
|
|
36
|
+
text: "unknown",
|
|
37
|
+
detail: "The driver's state has not been read",
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
const { health } = state;
|
|
41
|
+
const detail = [health.name, health.message].filter(Boolean).join(" · ");
|
|
42
|
+
if (health.state === "stale") {
|
|
43
|
+
return { health: "stale", text: "stale", detail };
|
|
44
|
+
}
|
|
45
|
+
if (store.untimedState(health.quality) !== "live") {
|
|
46
|
+
return { health: "stale", text: `stale, was ${health.state}`, detail };
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
health: health.state,
|
|
50
|
+
text: health.state === "ok" ? "OK" : health.state,
|
|
51
|
+
detail,
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/** The devices whose driver state this build reads: the ones a page listing health asks for. */
|
|
56
|
+
export const devicesWithHealth = (store: Store) =>
|
|
57
|
+
store.manifest.devices.filter((device) => device.health).map(({ id }) => id);
|
|
58
|
+
|
|
59
|
+
export const healthBadge = (health: HealthView) =>
|
|
60
|
+
h(
|
|
61
|
+
"span",
|
|
62
|
+
{ class: `badge h-${health.health}`, title: health.detail },
|
|
63
|
+
health.text,
|
|
64
|
+
);
|
package/src/ui/index.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { dirname, resolve } from "node:path";
|
|
3
|
+
import { html } from "./page";
|
|
4
|
+
import { cacheSuccess } from "./success-cache";
|
|
5
|
+
|
|
6
|
+
const build = async () => {
|
|
7
|
+
const result = await Bun.build({
|
|
8
|
+
entrypoints: [
|
|
9
|
+
resolve(
|
|
10
|
+
dirname(createRequire(import.meta.url).resolve("@tsplc/debug")),
|
|
11
|
+
"../src/ui/main.ts",
|
|
12
|
+
),
|
|
13
|
+
],
|
|
14
|
+
target: "browser",
|
|
15
|
+
// Workspace packages resolve to their sources, as they do for the host, so no build is needed first.
|
|
16
|
+
conditions: ["bun"],
|
|
17
|
+
minify: true,
|
|
18
|
+
});
|
|
19
|
+
const [output] = result.outputs;
|
|
20
|
+
if (!result.success || !output) {
|
|
21
|
+
throw new AggregateError(result.logs, "Bundling the debugger UI failed");
|
|
22
|
+
}
|
|
23
|
+
return { html, script: await output.text() };
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/** The browser UI: serve `html` at `GET /` and `script` at `GET /ui.js`. Bundled on first call, then kept once it succeeds. */
|
|
27
|
+
export const loadUi = cacheSuccess(build);
|
package/src/ui/jobs.ts
ADDED
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import type { JobState } from "../api";
|
|
2
|
+
import { empty, h, table, type View } from "./dom";
|
|
3
|
+
import {
|
|
4
|
+
failedWhileIdle,
|
|
5
|
+
failureName,
|
|
6
|
+
formatDuration,
|
|
7
|
+
isProgramJob,
|
|
8
|
+
jobStatus,
|
|
9
|
+
valueStateLabels,
|
|
10
|
+
} from "./format";
|
|
11
|
+
import { pathLink, recordSourceLink, sourceLink } from "./links";
|
|
12
|
+
import type { Page } from "./pages";
|
|
13
|
+
import { requestStatus } from "./request-trace";
|
|
14
|
+
import { href, type JobFilter, jobFilters, type Place } from "./routes";
|
|
15
|
+
import type { Store } from "./store";
|
|
16
|
+
|
|
17
|
+
export const isActive = (job: JobState) =>
|
|
18
|
+
job.busy === true || failedWhileIdle(job);
|
|
19
|
+
|
|
20
|
+
/** The step a busy job waits at, when its details were read. */
|
|
21
|
+
const waitingOn = (store: Store, job: JobState) => {
|
|
22
|
+
if (job.unread) {
|
|
23
|
+
return h("span", { class: "dim" }, "details not read (too many busy jobs)");
|
|
24
|
+
}
|
|
25
|
+
if (!job.current) {
|
|
26
|
+
return h("span", { class: "dim" }, "—");
|
|
27
|
+
}
|
|
28
|
+
return h(
|
|
29
|
+
"span",
|
|
30
|
+
{},
|
|
31
|
+
h("span", { class: "tag" }, job.current.kind),
|
|
32
|
+
" ",
|
|
33
|
+
h("code", {}, job.current.text),
|
|
34
|
+
" ",
|
|
35
|
+
sourceLink(store, job.current.range),
|
|
36
|
+
);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/** One job: what it is, where it is waiting and what it asked the backend. */
|
|
40
|
+
export const jobRow = (
|
|
41
|
+
store: Store,
|
|
42
|
+
job: JobState,
|
|
43
|
+
{ highlighted }: { highlighted: boolean },
|
|
44
|
+
) => {
|
|
45
|
+
const definition = store.manifest.jobs.find(
|
|
46
|
+
(candidate) => candidate.id === job.id,
|
|
47
|
+
);
|
|
48
|
+
const status = jobStatus(job);
|
|
49
|
+
const trace = job.request?.trace;
|
|
50
|
+
const state = store.untimedState(job.quality);
|
|
51
|
+
return h(
|
|
52
|
+
"tr",
|
|
53
|
+
{ class: highlighted ? "highlight" : undefined, id: `job-${job.id}` },
|
|
54
|
+
h(
|
|
55
|
+
"td",
|
|
56
|
+
{},
|
|
57
|
+
h("b", { class: "mono" }, definition?.name ?? `job ${job.id}`),
|
|
58
|
+
definition ? h("div", {}, sourceLink(store, definition.declaration)) : "",
|
|
59
|
+
),
|
|
60
|
+
h(
|
|
61
|
+
"td",
|
|
62
|
+
{},
|
|
63
|
+
definition?.instance
|
|
64
|
+
? pathLink(definition.instance)
|
|
65
|
+
: h("span", { class: "dim" }, "—"),
|
|
66
|
+
),
|
|
67
|
+
h(
|
|
68
|
+
"td",
|
|
69
|
+
{},
|
|
70
|
+
h(
|
|
71
|
+
"span",
|
|
72
|
+
{
|
|
73
|
+
class: `st st-${status}`,
|
|
74
|
+
title:
|
|
75
|
+
status === "unknown"
|
|
76
|
+
? "Not read: shown jobs are read through the login"
|
|
77
|
+
: undefined,
|
|
78
|
+
},
|
|
79
|
+
status,
|
|
80
|
+
),
|
|
81
|
+
state === "live" || job.busy === null
|
|
82
|
+
? ""
|
|
83
|
+
: h(
|
|
84
|
+
"span",
|
|
85
|
+
{ class: `meta s-${state}` },
|
|
86
|
+
` ${valueStateLabels[state]}`,
|
|
87
|
+
),
|
|
88
|
+
),
|
|
89
|
+
h("td", { class: "await" }, waitingOn(store, job)),
|
|
90
|
+
h(
|
|
91
|
+
"td",
|
|
92
|
+
{ class: "mono num" },
|
|
93
|
+
job.elapsedMs === undefined ? "—" : formatDuration(job.elapsedMs),
|
|
94
|
+
),
|
|
95
|
+
h(
|
|
96
|
+
"td",
|
|
97
|
+
{ class: "err" },
|
|
98
|
+
job.failure
|
|
99
|
+
? h(
|
|
100
|
+
"span",
|
|
101
|
+
{ title: `Unhandled at ${job.failure.at}` },
|
|
102
|
+
failureName(store.manifest, job.failure),
|
|
103
|
+
" ",
|
|
104
|
+
recordSourceLink(store, job.failure.source),
|
|
105
|
+
)
|
|
106
|
+
: "",
|
|
107
|
+
),
|
|
108
|
+
h(
|
|
109
|
+
"td",
|
|
110
|
+
{ class: "nowrap" },
|
|
111
|
+
job.request
|
|
112
|
+
? h(
|
|
113
|
+
"span",
|
|
114
|
+
{},
|
|
115
|
+
h(
|
|
116
|
+
"a",
|
|
117
|
+
{
|
|
118
|
+
href: href({ route: "requests", seq: trace?.seq }),
|
|
119
|
+
class: "mono",
|
|
120
|
+
},
|
|
121
|
+
`${job.request.service} #${job.request.sequence}`,
|
|
122
|
+
),
|
|
123
|
+
" ",
|
|
124
|
+
trace
|
|
125
|
+
? requestStatus(trace)
|
|
126
|
+
: h("span", { class: "dim" }, "no trace"),
|
|
127
|
+
trace?.durationMs === undefined
|
|
128
|
+
? ""
|
|
129
|
+
: h(
|
|
130
|
+
"span",
|
|
131
|
+
{ class: "mono dim" },
|
|
132
|
+
` ${formatDuration(trace.durationMs)}`,
|
|
133
|
+
),
|
|
134
|
+
)
|
|
135
|
+
: h("span", { class: "dim" }, "—"),
|
|
136
|
+
),
|
|
137
|
+
);
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
export const jobTable = (rows: HTMLElement[]) =>
|
|
141
|
+
table(
|
|
142
|
+
[
|
|
143
|
+
"Function",
|
|
144
|
+
"Instance",
|
|
145
|
+
"State",
|
|
146
|
+
"Waiting on",
|
|
147
|
+
"Elapsed",
|
|
148
|
+
"Error",
|
|
149
|
+
"Request",
|
|
150
|
+
],
|
|
151
|
+
h("tbody", {}, ...rows),
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
const filters: Record<
|
|
155
|
+
JobFilter,
|
|
156
|
+
{ label: string; keep: (job: JobState) => boolean }
|
|
157
|
+
> = {
|
|
158
|
+
all: { label: "All", keep: () => true },
|
|
159
|
+
busy: { label: "Busy", keep: (job) => job.busy === true },
|
|
160
|
+
failed: { label: "Failed", keep: failedWhileIdle },
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
export const jobsView = (
|
|
164
|
+
store: Store,
|
|
165
|
+
page: Page,
|
|
166
|
+
{
|
|
167
|
+
id: highlighted,
|
|
168
|
+
filter: initial = "all",
|
|
169
|
+
}: Extract<Place, { route: "jobs" }>,
|
|
170
|
+
): View => {
|
|
171
|
+
let filter = initial;
|
|
172
|
+
const generated = new Set(
|
|
173
|
+
store.manifest.jobs
|
|
174
|
+
.filter((job) => !isProgramJob(job))
|
|
175
|
+
.map((job) => job.id),
|
|
176
|
+
);
|
|
177
|
+
const generatedToggle = h("input", {
|
|
178
|
+
type: "checkbox",
|
|
179
|
+
checked: highlighted !== undefined && generated.has(highlighted),
|
|
180
|
+
});
|
|
181
|
+
const shown = (job: { id: number }) =>
|
|
182
|
+
generatedToggle.checked || !generated.has(job.id);
|
|
183
|
+
const bar = h("div", { class: "tabs" });
|
|
184
|
+
const body = h("div");
|
|
185
|
+
const render = () => {
|
|
186
|
+
bar.replaceChildren(
|
|
187
|
+
...jobFilters.map((key) =>
|
|
188
|
+
h(
|
|
189
|
+
"button",
|
|
190
|
+
{
|
|
191
|
+
class: `tab${key === filter ? " on" : ""}`,
|
|
192
|
+
onclick: () => {
|
|
193
|
+
filter = key;
|
|
194
|
+
history.replaceState(
|
|
195
|
+
null,
|
|
196
|
+
"",
|
|
197
|
+
href({ route: "jobs", filter: key }),
|
|
198
|
+
);
|
|
199
|
+
render();
|
|
200
|
+
},
|
|
201
|
+
},
|
|
202
|
+
filters[key].label,
|
|
203
|
+
h(
|
|
204
|
+
"span",
|
|
205
|
+
{ class: "n" },
|
|
206
|
+
String(
|
|
207
|
+
[...store.jobs.values()].filter(
|
|
208
|
+
(job) => shown(job) && filters[key].keep(job),
|
|
209
|
+
).length,
|
|
210
|
+
),
|
|
211
|
+
),
|
|
212
|
+
),
|
|
213
|
+
),
|
|
214
|
+
h("label", { class: "check" }, generatedToggle, "show generated"),
|
|
215
|
+
);
|
|
216
|
+
const jobs = [...store.jobs.values()]
|
|
217
|
+
.filter((job) => shown(job) && filters[filter].keep(job))
|
|
218
|
+
.sort((a, b) => Number(isActive(b)) - Number(isActive(a)) || a.id - b.id);
|
|
219
|
+
body.replaceChildren(
|
|
220
|
+
jobs.length
|
|
221
|
+
? jobTable(
|
|
222
|
+
jobs.map((job) =>
|
|
223
|
+
jobRow(store, job, { highlighted: job.id === highlighted }),
|
|
224
|
+
),
|
|
225
|
+
)
|
|
226
|
+
: empty("No jobs match."),
|
|
227
|
+
);
|
|
228
|
+
};
|
|
229
|
+
const showJobs = () =>
|
|
230
|
+
page.show({
|
|
231
|
+
jobs: store.manifest.jobs.filter(shown).map(({ id }) => id),
|
|
232
|
+
});
|
|
233
|
+
generatedToggle.addEventListener("change", () => {
|
|
234
|
+
showJobs();
|
|
235
|
+
render();
|
|
236
|
+
});
|
|
237
|
+
render();
|
|
238
|
+
showJobs();
|
|
239
|
+
return {
|
|
240
|
+
element: h(
|
|
241
|
+
"div",
|
|
242
|
+
{ class: "page" },
|
|
243
|
+
h("h1", {}, "Jobs"),
|
|
244
|
+
h(
|
|
245
|
+
"p",
|
|
246
|
+
{ class: "hint" },
|
|
247
|
+
"Busy and idle come from the trace when it is on; otherwise each listed job's busy flag is read through the login, and the details of busy ones. Failures are the program's unhandled exceptions.",
|
|
248
|
+
),
|
|
249
|
+
bar,
|
|
250
|
+
body,
|
|
251
|
+
),
|
|
252
|
+
update(topics) {
|
|
253
|
+
if (
|
|
254
|
+
topics.has("jobs") ||
|
|
255
|
+
topics.has("stream") ||
|
|
256
|
+
topics.has("session") ||
|
|
257
|
+
topics.has("timeline")
|
|
258
|
+
) {
|
|
259
|
+
render();
|
|
260
|
+
}
|
|
261
|
+
},
|
|
262
|
+
};
|
|
263
|
+
};
|
package/src/ui/links.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { SourceRange } from "../manifest";
|
|
2
|
+
import { h } from "./dom";
|
|
3
|
+
import { recordLocation, sourceLocation } from "./format";
|
|
4
|
+
import { href } from "./routes";
|
|
5
|
+
import type { Store } from "./store";
|
|
6
|
+
|
|
7
|
+
const locationLink = (
|
|
8
|
+
location: { href?: string },
|
|
9
|
+
title: string,
|
|
10
|
+
text: string,
|
|
11
|
+
) =>
|
|
12
|
+
location.href
|
|
13
|
+
? h(
|
|
14
|
+
"a",
|
|
15
|
+
{
|
|
16
|
+
class: "src",
|
|
17
|
+
href: location.href,
|
|
18
|
+
title: `Open ${title} in VS Code`,
|
|
19
|
+
},
|
|
20
|
+
text,
|
|
21
|
+
)
|
|
22
|
+
: h("span", { class: "src", title }, text);
|
|
23
|
+
|
|
24
|
+
export const sourceLink = (store: Store, range: SourceRange, text?: string) => {
|
|
25
|
+
const location = sourceLocation(
|
|
26
|
+
store.manifest,
|
|
27
|
+
store.session.projectRoot,
|
|
28
|
+
range,
|
|
29
|
+
);
|
|
30
|
+
return locationLink(location, location.label, text ?? location.label);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/** A telemetry record's `source`, a project-relative `file:line`. */
|
|
34
|
+
export const recordSourceLink = (store: Store, source: string) => {
|
|
35
|
+
const location = recordLocation(store.session.projectRoot, source);
|
|
36
|
+
return locationLink(location, source, location.label);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export const pathLink = (path: string, text: Node | string = path) =>
|
|
40
|
+
h(
|
|
41
|
+
"a",
|
|
42
|
+
{
|
|
43
|
+
class: "path",
|
|
44
|
+
href: href({ route: "variables", path }),
|
|
45
|
+
title: `Show ${path} in Variables`,
|
|
46
|
+
},
|
|
47
|
+
text,
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
export const whyLink = (path: string) =>
|
|
51
|
+
h(
|
|
52
|
+
"a",
|
|
53
|
+
{
|
|
54
|
+
class: "why-link",
|
|
55
|
+
href: href({ route: "why", path }),
|
|
56
|
+
title: "Why does it have this value?",
|
|
57
|
+
},
|
|
58
|
+
"Why?",
|
|
59
|
+
);
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { h } from "./dom";
|
|
2
|
+
import {
|
|
3
|
+
formatReadAt,
|
|
4
|
+
formatValue,
|
|
5
|
+
type ValueState,
|
|
6
|
+
valueStateLabels,
|
|
7
|
+
} from "./format";
|
|
8
|
+
import type { Store } from "./store";
|
|
9
|
+
import type { TreeNode } from "./tree";
|
|
10
|
+
|
|
11
|
+
const setText = (element: HTMLElement, text: string) => {
|
|
12
|
+
if (element.textContent !== text) {
|
|
13
|
+
element.textContent = text;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
const setClass = (element: HTMLElement, name: string) => {
|
|
17
|
+
if (element.className !== name) {
|
|
18
|
+
element.className = name;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/** A variable's value and its quality and age, kept current by `update()` from the store. */
|
|
23
|
+
export class LiveValue {
|
|
24
|
+
readonly value = h("span");
|
|
25
|
+
readonly meta = h("span");
|
|
26
|
+
|
|
27
|
+
constructor(
|
|
28
|
+
private readonly store: Store,
|
|
29
|
+
readonly node: TreeNode,
|
|
30
|
+
) {
|
|
31
|
+
this.update();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Whether the stream should carry this path. */
|
|
35
|
+
get subscribed() {
|
|
36
|
+
return this.node.readable && !this.node.constant;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
update() {
|
|
40
|
+
if (this.node.constant) {
|
|
41
|
+
return this.show(
|
|
42
|
+
"constant",
|
|
43
|
+
formatValue(
|
|
44
|
+
this.store.manifest,
|
|
45
|
+
this.node.type,
|
|
46
|
+
this.node.constant.value,
|
|
47
|
+
),
|
|
48
|
+
"constant",
|
|
49
|
+
"",
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
if (!this.node.readable) {
|
|
53
|
+
return this.show(
|
|
54
|
+
"unavailable",
|
|
55
|
+
"—",
|
|
56
|
+
"not readable",
|
|
57
|
+
"This build can't read it from the controller",
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
const { sample, state } = this.store.live(this.node.path);
|
|
61
|
+
if (!sample) {
|
|
62
|
+
return this.show("unavailable", "—", "not read", "Not read yet");
|
|
63
|
+
}
|
|
64
|
+
const meta =
|
|
65
|
+
state === "unavailable" || state === "bad"
|
|
66
|
+
? valueStateLabels[state]
|
|
67
|
+
: `${valueStateLabels[state]} · ${formatReadAt(sample.receivedAt)}`;
|
|
68
|
+
this.show(
|
|
69
|
+
state,
|
|
70
|
+
formatValue(this.store.manifest, this.node.type, sample.value),
|
|
71
|
+
meta,
|
|
72
|
+
`${sample.status}\nread ${sample.receivedAt}`,
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
private show(state: ValueState, value: string, meta: string, title: string) {
|
|
77
|
+
setClass(this.value, `value s-${state}`);
|
|
78
|
+
setClass(this.meta, `meta s-${state}`);
|
|
79
|
+
setText(this.value, value);
|
|
80
|
+
setText(this.meta, meta);
|
|
81
|
+
if (this.meta.title !== title) {
|
|
82
|
+
this.meta.title = title;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|