@@ -249,21 +249,23 @@ export class PlutoNotebookController {
249249 private startExecution (
250250 cellId : CellId ,
251251 notebook : vscode . NotebookDocument
252- ) : vscode . NotebookCellExecution {
252+ ) : { execution : vscode . NotebookCellExecution ; cell : vscode . NotebookCell } {
253+ const cell = this . getCellByPlutoId ( notebook , cellId ) ;
254+ if ( ! cell ) {
255+ throw new Error ( "Can not determine notebook cell" ) ;
256+ }
253257 let execution = this . activeExecutions . get ( cellId ) ;
258+
254259 if ( ! execution ) {
255260 this . outputChannel . appendLine (
256261 `[EXEC INIT] Starting initial execution for cell ${ cellId } `
257262 ) ;
258- const notebookCell = this . getCellByPlutoId ( notebook , cellId ) ;
259- if ( ! notebookCell ) {
260- throw new Error ( "Can not determine notebook cell" ) ;
261- }
262- execution = this . controller . createNotebookCellExecution ( notebookCell ) ;
263+
264+ execution = this . controller . createNotebookCellExecution ( cell ) ;
263265 this . activeExecutions . set ( cellId , execution ) ;
264266 execution . start ( Date . now ( ) ) ;
265267 }
266- return execution ;
268+ return { execution, cell } ;
267269 }
268270 /**
269271 * Handles cell-specific patch updates (execution status, output, logs).
@@ -323,20 +325,26 @@ export class PlutoNotebookController {
323325 }
324326 if ( isStarting ) {
325327 // Start execution
326- const execution = this . startExecution ( cellId , notebook ) ;
327- execution . replaceOutput ( [ formatCellOutput ( currentCellState ) ] ) ;
328+ const { execution } = this . startExecution ( cellId , notebook ) ;
329+ const formatted = formatCellOutput ( currentCellState ) ;
330+ execution . replaceOutput ( [ formatted ] ) ;
328331 }
329332
330333 // 2. Update Cell Output (only if an execution object exists)
331334 if ( segment2 === "output" ) {
332335 // Handle final output/result update
333- const execution = this . startExecution ( cellId , notebook ) ;
336+ const { execution, cell } = this . startExecution ( cellId , notebook ) ;
334337 // execution.replaceOutput([formatCellOutput(currentCellState)]);
335338
336339 this . outputChannel . appendLine (
337340 `[OUTPUT] Cell ${ cellId } for notebook ${ notebook . uri } output updated.`
338341 ) ;
339-
342+ // TODO HERE WE NEED TO CHECK IF VSCODE NOTEBOOK HAS THE OUTPUT CELL OR NOT
343+ // IF NOT, WE NEED TO ADD IT (BECAUSE IT MAY HAVE BEEN CLEARED)
344+ // OTHERWISE, IT WILL NOT SHOW UP
345+ if ( cell . outputs . length === 0 ) {
346+ execution . replaceOutput ( [ formatCellOutput ( currentCellState ) ] ) ;
347+ }
340348 execution . end ( true , Date . now ( ) ) ;
341349 this . activeExecutions . delete ( cellId ) ;
342350 this . outputChannel . appendLine ( `[EXEC END] Cell ${ cellId } finished.` ) ;
@@ -747,7 +755,7 @@ export class PlutoNotebookController {
747755 }
748756
749757 // Ensure there is at least an initial execution object for this cell
750- const execution = this . startExecution ( cellId , notebook ) ;
758+ const { execution } = this . startExecution ( cellId , notebook ) ;
751759
752760 try {
753761 // Get or create worker - this will start the server if needed
0 commit comments