(
kernelConnection: Kernel.IKernelConnection,
code: string,
onStarted: () => void,
onOutput: (output: NotebookCellOutput) => void
)
| 748 | } |
| 749 | |
| 750 | export function executeSilentlyAndEmitOutput( |
| 751 | kernelConnection: Kernel.IKernelConnection, |
| 752 | code: string, |
| 753 | onStarted: () => void, |
| 754 | onOutput: (output: NotebookCellOutput) => void |
| 755 | ) { |
| 756 | code = code.replace(/\r\n/g, '\n'); |
| 757 | |
| 758 | const request = kernelConnection.requestExecute( |
| 759 | { |
| 760 | code, |
| 761 | silent: false, |
| 762 | stop_on_error: false, |
| 763 | allow_stdin: false, |
| 764 | store_history: false |
| 765 | }, |
| 766 | true |
| 767 | ); |
| 768 | const started = once(onStarted); |
| 769 | request.onIOPub = (msg) => { |
| 770 | started(); |
| 771 | if (jupyterLab.KernelMessage.isStreamMsg(msg)) { |
| 772 | onOutput( |
| 773 | cellOutputToVSCCellOutput({ |
| 774 | output_type: 'stream', |
| 775 | name: msg.content.name, |
| 776 | text: msg.content.text |
| 777 | }) |
| 778 | ); |
| 779 | } else if (jupyterLab.KernelMessage.isExecuteResultMsg(msg)) { |
| 780 | onOutput( |
| 781 | cellOutputToVSCCellOutput({ |
| 782 | output_type: 'execute_result', |
| 783 | data: msg.content.data, |
| 784 | metadata: msg.content.metadata, |
| 785 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 786 | transient: msg.content.transient as any, // NOSONAR |
| 787 | execution_count: msg.content.execution_count |
| 788 | }) |
| 789 | ); |
| 790 | } else if (jupyterLab.KernelMessage.isDisplayDataMsg(msg)) { |
| 791 | onOutput( |
| 792 | cellOutputToVSCCellOutput({ |
| 793 | output_type: 'display_data', |
| 794 | data: handleTensorBoardDisplayDataOutput(msg.content.data), |
| 795 | metadata: msg.content.metadata, |
| 796 | transient: msg.content.transient |
| 797 | }) |
| 798 | ); |
| 799 | } else if (jupyterLab.KernelMessage.isUpdateDisplayDataMsg(msg)) { |
| 800 | onOutput( |
| 801 | cellOutputToVSCCellOutput({ |
| 802 | output_type: 'display_data', |
| 803 | data: handleTensorBoardDisplayDataOutput(msg.content.data), |
| 804 | metadata: msg.content.metadata, |
| 805 | transient: msg.content.transient |
| 806 | }) |
| 807 | ); |
no test coverage detected