From 6c6f6c4b130b667f34ac6b16c73b1e69172fbc7f Mon Sep 17 00:00:00 2001 From: Wasim Lorgat Date: Wed, 11 Dec 2024 20:36:40 +0200 Subject: [PATCH] Fix "view as scrollable element" not working (#5680) The issue was due to cell output metadata being set to `undefined` by the Positron notebook controllers, causing the `scrollable` metadata to not be set here: https://github.com/posit-dev/positron/blob/54d791da6b5e015ff03a596a848c8893cf90d3bd/src/vs/workbench/contrib/notebook/browser/view/renderers/backLayerWebView.ts#L766-L769 We now set metadata and also set `outputType` since it also makes life easier for the ipynb serializer: https://github.com/posit-dev/positron/blob/3a8978af98c6b8b03a98916a9bf8b91ba7070df3/extensions/ipynb/src/serializers.ts#L182 ### QA Notes 1. Run a Python notebook cell with the following code: ```python # code with error def divide_numbers(numbers): result = [] for num in numbers: result.append(10 / num) return result numbers_to_divide = [2, 4, 0, 5, 7] try: divide_numbers(numbers_to_divide) except Exception as e: error_message = f"Error: {e}\n" * 50 # Repeat error message raise RuntimeError(error_message) ``` 2. Click "View as scrollable element" - it should work. 3. Also try the "Notebook: Toggle scrollable element" command with the cell selected. --- .../src/notebookController.ts | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/extensions/positron-notebook-controllers/src/notebookController.ts b/extensions/positron-notebook-controllers/src/notebookController.ts index 29fa383712c..8e741ad9f4d 100644 --- a/extensions/positron-notebook-controllers/src/notebookController.ts +++ b/extensions/positron-notebook-controllers/src/notebookController.ts @@ -10,8 +10,21 @@ import { log, setHasRunningNotebookSessionContext } from './extension'; import { ResourceMap } from './map'; import { getNotebookSession, isActiveNotebookEditorUri } from './utils'; -/** The type of a Jupyter notebook cell output. */ +/** + * The type of a Jupyter notebook cell output. + * + * Used by the ipynb notebook serializer (extensions/ipynb/src/serializers.ts) to convert from + * VSCode notebook cell outputs to Jupyter notebook cell outputs. + * + * See: https://jupyter-client.readthedocs.io/en/latest/messaging.html + */ enum NotebookCellOutputType { + /** An error occurred during an execution. */ + Error = 'error', + + /** Output from one of the standard streams (stdout or stderr). */ + Stream = 'stream', + /** One of possibly many outputs related to an execution. */ DisplayData = 'display_data', @@ -600,7 +613,9 @@ async function handleRuntimeMessageStream( if (lastOutputItems && lastOutputItems.every(item => item.mime === cellOutputItem.mime)) { await execution.appendOutputItems([cellOutputItem], lastOutput); } else { - const cellOutput = new vscode.NotebookCellOutput([cellOutputItem]); + const cellOutput = new vscode.NotebookCellOutput( + [cellOutputItem], { outputType: NotebookCellOutputType.Stream }, + ); await execution.appendOutput(cellOutput); } } @@ -621,6 +636,6 @@ async function handleRuntimeMessageError( message: message.message, stack: message.traceback.join('\n'), }) - ]); + ], { outputType: NotebookCellOutputType.Error }); await execution.appendOutput(cellOutput); }