@@ -43,6 +43,7 @@ import { QuartoVisualEditor, VisualEditorProvider } from "../editor/editor";
4343import {
4444 blockHasExecutor ,
4545 blockIsExecutable ,
46+ cellMetadataForBlock ,
4647 codeWithoutOptionsFromBlock ,
4748 executeInteractive ,
4849 executeSelectionInteractive ,
@@ -177,7 +178,8 @@ class RunCurrentCellCommand extends RunCommand implements Command {
177178 if ( executor ) {
178179 const code = codeWithoutOptionsFromBlock ( block ) ;
179180 const ranges = block . range ? [ block . range ] : undefined ;
180- await executeInteractive ( executor , [ code ] , editor . document , ranges ) ;
181+ const metadata = cellMetadataForBlock ( block ) ;
182+ await executeInteractive ( executor , [ code ] , editor . document , ranges , metadata ? [ metadata ] : undefined ) ;
181183 }
182184 }
183185 }
@@ -306,7 +308,8 @@ class RunCurrentCommand extends RunCommand implements Command {
306308
307309 if ( resolveToRunCell ) {
308310 const code = codeWithoutOptionsFromBlock ( block ) ;
309- await executeInteractive ( executor , [ code ] , editor . document ) ;
311+ const metadata = cellMetadataForBlock ( block ) ;
312+ await executeInteractive ( executor , [ code ] , editor . document , undefined , metadata ? [ metadata ] : undefined ) ;
310313 } else {
311314 // submit
312315 const executed = await executeSelectionInteractive ( executor ) ;
@@ -500,21 +503,24 @@ class RunCellsAboveCommand extends RunCommand implements Command {
500503
501504 const executor = await this . cellExecutorForLanguage ( language , editor . document , this . engine_ ) ;
502505 if ( executor ) {
503- // accumulate code and ranges
506+ // accumulate code, ranges, and metadata
504507 const code : string [ ] = [ ] ;
505508 const ranges : Range [ ] = [ ] ;
509+ const metadata : ( Record < string , unknown > | undefined ) [ ] = [ ] ;
506510 for ( const blk of blocks . filter (
507511 isExecutableLanguageBlockOf ( language )
508512 ) as Array < TokenMath | TokenCodeBlock > ) {
509513 code . push ( codeWithoutOptionsFromBlock ( blk ) ) ;
514+ metadata . push ( cellMetadataForBlock ( blk ) ) ;
510515 if ( blk . range ) {
511516 ranges . push ( blk . range ) ;
512517 }
513518 }
514519
515520 // execute (only pass ranges if we collected the same number as code blocks)
516521 const validRanges = ranges . length === code . length ? ranges : undefined ;
517- await executeInteractive ( executor , code , editor . document , validRanges ) ;
522+ const validMetadata = metadata . some ( m => m !== undefined ) ? metadata . map ( m => m ?? { } ) : undefined ;
523+ await executeInteractive ( executor , code , editor . document , validRanges , validMetadata ) ;
518524 }
519525 }
520526 }
@@ -565,6 +571,7 @@ class RunCellsBelowCommand extends RunCommand implements Command {
565571
566572 const blocks : string [ ] = [ ] ;
567573 const ranges : Range [ ] = [ ] ;
574+ const metadata : ( Record < string , unknown > | undefined ) [ ] = [ ] ;
568575 for ( const blk of tokens . filter ( ( token ?: Token ) => blockIsExecutable ( this . host_ , token ) ) as Array < TokenMath | TokenCodeBlock > ) {
569576 // skip if the cell is above or at the cursor
570577 if ( blk . range && line < blk . range . start . line ) {
@@ -577,6 +584,7 @@ class RunCellsBelowCommand extends RunCommand implements Command {
577584 if ( blockLanguage === language ) {
578585 blocks . push ( codeWithoutOptionsFromBlock ( blk ) ) ;
579586 ranges . push ( blk . range ) ;
587+ metadata . push ( cellMetadataForBlock ( blk ) ) ;
580588 }
581589 }
582590 }
@@ -585,7 +593,8 @@ class RunCellsBelowCommand extends RunCommand implements Command {
585593 const executor = await this . cellExecutorForLanguage ( language , editor . document , this . engine_ ) ;
586594 if ( executor ) {
587595 const validRanges = ranges . length === blocks . length ? ranges : undefined ;
588- await executeInteractive ( executor , blocks , editor . document , validRanges ) ;
596+ const validMetadata = metadata . some ( m => m !== undefined ) ? metadata . map ( m => m ?? { } ) : undefined ;
597+ await executeInteractive ( executor , blocks , editor . document , validRanges , validMetadata ) ;
589598 }
590599 }
591600 }
@@ -632,13 +641,15 @@ class RunAllCellsCommand extends RunCommand implements Command {
632641 let language : string | undefined ;
633642 const blocks : string [ ] = [ ] ;
634643 const ranges : Range [ ] = [ ] ;
644+ const metadata : ( Record < string , unknown > | undefined ) [ ] = [ ] ;
635645 for ( const blk of tokens . filter ( ( token ?: Token ) => blockIsExecutable ( this . host_ , token ) ) as Array < TokenMath | TokenCodeBlock > ) {
636646 const blockLanguage = languageNameFromBlock ( blk ) ;
637647 if ( ! language ) {
638648 language = blockLanguage ;
639649 }
640650 if ( blockLanguage === language ) {
641651 blocks . push ( codeWithoutOptionsFromBlock ( blk ) ) ;
652+ metadata . push ( cellMetadataForBlock ( blk ) ) ;
642653 if ( blk . range ) {
643654 ranges . push ( blk . range ) ;
644655 }
@@ -649,7 +660,8 @@ class RunAllCellsCommand extends RunCommand implements Command {
649660 if ( executor ) {
650661 // only pass ranges if we collected the same number as code blocks
651662 const validRanges = ranges . length === blocks . length ? ranges : undefined ;
652- await executeInteractive ( executor , blocks , editor . document , validRanges ) ;
663+ const validMetadata = metadata . some ( m => m !== undefined ) ? metadata . map ( m => m ?? { } ) : undefined ;
664+ await executeInteractive ( executor , blocks , editor . document , validRanges , validMetadata ) ;
653665 }
654666 }
655667 }
@@ -743,7 +755,8 @@ async function runAdjacentBlock(host: ExtensionHost, editor: TextEditor, engine:
743755 const executor = await host . cellExecutorForLanguage ( language , editor . document , engine ) ;
744756 if ( executor ) {
745757 const ranges = block . range ? [ block . range ] : undefined ;
746- await executeInteractive ( executor , [ codeWithoutOptionsFromBlock ( block ) ] , editor . document , ranges ) ;
758+ const metadata = cellMetadataForBlock ( block ) ;
759+ await executeInteractive ( executor , [ codeWithoutOptionsFromBlock ( block ) ] , editor . document , ranges , metadata ? [ metadata ] : undefined ) ;
747760 }
748761}
749762
0 commit comments