Skip to content

Commit ad6e488

Browse files
committed
fix: show outputs on reopen
1 parent 5a20ca7 commit ad6e488

3 files changed

Lines changed: 63 additions & 37 deletions

File tree

renderer/components/PlutoOutput.tsx

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
useEffect,
1212
setup_mathjax,
1313
useState,
14+
useErrorBoundary,
1415
} from "@plutojl/rainbow/ui";
1516
import { type RendererContext } from "vscode-notebook-renderer";
1617

@@ -40,21 +41,23 @@ const cutMime = (s: { msg: string }, l = 88) => {
4041

4142
export function PlutoOutput({ state, context }: PlutoOutputProps) {
4243
useMathjaxEffect();
44+
const [error, resetError] = useErrorBoundary();
45+
4346
const [localState, setLocalState] = useState(state);
4447
const [progress, setProgress] = useState<any>(null);
4548
const [terminal, setTerminal] = useState<any>(null);
4649
const [logs, setLogs] = useState<any>(null);
4750
useEffect(() => {
4851
// Listen for messages from the controller
4952
const d = context.onDidReceiveMessage?.((message) => {
50-
if (message.cell_id !== state.cell_id) {
53+
if (message.cell_id !== localState.cell_id) {
5154
return;
5255
}
5356
// Placeholder: Handle different message types from controller
5457
switch (message.type) {
5558
case "setState": {
5659
const state = message.state as CellResultData;
57-
setLocalState(state);
60+
setLocalState({ ...state });
5861

5962
const logs = state.logs.filter((log) => {
6063
return (
@@ -82,45 +85,51 @@ export function PlutoOutput({ state, context }: PlutoOutputProps) {
8285
});
8386
return () => d?.dispose();
8487
}, [state.cell_id, context]);
85-
86-
return html`
87-
${
88-
state.running && progress
89-
? html`<div>
90-
<label for=${`progress_${state.cell_id}`}> ${progress}% </label
91-
><progress
92-
style="width: 240px;"
93-
id=${`progress_${state.cell_id}`}
94-
max="100"
95-
value=${progress}
96-
></progress>
97-
</div>`
98-
: null
88+
if (error) {
89+
return html`<div onclick=${resetError}>
90+
An error occured. Click <button onClick=${resetError}>here</button> to
91+
reset the view
92+
<details>
93+
<summary>View error</summary>
94+
(Thank you for using a pre-release. This is on us. Please copy-paste
95+
this and send it our way! Sorry again!)
96+
<pre>${JSON.stringify(error)}</pre>
97+
</details>
98+
</div>`;
9999
}
100-
<${OutputBody}
101-
persist_js_state="${true}"
100+
return html` ${localState.running && progress
101+
? html`<div>
102+
<label for=${`progress_${localState.cell_id}`}> ${progress}% </label
103+
><progress
104+
style="width: 240px;"
105+
id=${`progress_${localState.cell_id}`}
106+
max="100"
107+
value=${progress}
108+
></progress>
109+
</div>`
110+
: null}
111+
${localState.output?.mime
112+
? html`<${OutputBody}
113+
persist_js_state="${localState.output.persist_js_state}"
102114
body="${localState.output?.body}"
103115
mime="${localState.output?.mime}"
104116
sanitize_html="${false /* Maybe reconsider */}"
105-
></${OutputBody}>
106-
${
107-
terminal?.length
108-
? html`<details>
117+
></${OutputBody}>`
118+
: "Loading..."}
119+
${terminal?.length
120+
? html`<details>
109121
<summary>stdout</summary>
110122
<${ANSITextOutput}
111123
body="${terminal.map(cutMime).join("\n")}"
112124
></${ANSITextOutput}>
113125
</details>`
114-
: null
115-
}
116-
${
117-
logs?.length
118-
? html`<details open>
126+
: null}
127+
${logs?.length
128+
? html`<details open>
119129
<summary>Logs</summary>
120130
<${ANSITextOutput}
121131
body="${logs.map(cutMime).join("\n")}"
122132
></${ANSITextOutput}>
123133
</details>`
124-
: null
125-
}`;
134+
: null}`;
126135
}

src/controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ export class PlutoNotebookController {
270270
if (segment2 === "output") {
271271
// Handle final output/result update
272272
const execution = this.startExecution(cellId, notebook);
273-
execution.replaceOutput([formatCellOutput(currentCellState)]);
273+
// execution.replaceOutput([formatCellOutput(currentCellState)]);
274274

275275
this.outputChannel.appendLine(
276276
`[OUTPUT] Cell ${cellId} for notebook ${notebook.uri} output updated.`

src/plutoSerializer.ts

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,34 @@ export function createVsCodeCellFromPlutoCell(
5959
code,
6060
isMarkdown ? "markdown" : "julia"
6161
);
62-
const results = notebookData.cell_results[plutoCellId] ?? null;
63-
if (results !== null) {
64-
// Add output if available
65-
cellData.outputs = [formatCellOutput(results)];
66-
}
62+
63+
const results = notebookData.cell_results[plutoCellId] ?? {
64+
cell_id: plutoCellId,
65+
output: {
66+
body: undefined,
67+
has_pluto_hook_features: false,
68+
last_run_timestamp: 0,
69+
mime: "text/plain",
70+
persist_js_state: false,
71+
rootassignee: "",
72+
},
73+
running: false,
74+
errored: false,
75+
queued: true,
76+
runtime: 0,
77+
depends_on_disabled_cells: false,
78+
depends_on_skipped_cells: false,
79+
downstream_cells_map: {},
80+
precedence_heuristic: 0,
81+
logs: [],
82+
published_object_keys: [""],
83+
upstream_cells_map: {},
84+
};
85+
cellData.outputs = [formatCellOutput(results)];
6786
cellData.metadata = {
6887
pluto_cell_id: plutoCellId,
6988
...cellInput.metadata,
7089
};
71-
// TODO add outputs
72-
// cellData.outputs = [];
7390
return cellData;
7491
}
7592
/**

0 commit comments

Comments
 (0)