From 7a58ce8ab29b37393fb0027f151e2a2185477db1 Mon Sep 17 00:00:00 2001 From: Rich Chiodo Date: Tue, 31 Mar 2020 11:08:15 -0700 Subject: [PATCH] Support Update Display Data (#10874) * Bunch of logging and getting azureml debug bits * Get rid of second view * Implement update_display_data * Add news entry * Remove unnecessary jquery * Remove stylesheet from html * Add test * Add execute_result for update_display_data handling * Fix dependencies and only pull in the type from jupyterlab services * Fix importing jupyterlab services * Prettier format * Fix prettier again * Fix hygiene * Potential fix for functional failures * More hygiene issues * Fix functional tests * Fix unit tests --- .prettierrc.js | 1 + news/2 Fixes/10873.md | 1 + package.datascience-ui.dependencies.json | 1 + .../common/application/webPanels/webPanel.ts | 6 +- .../application/webPanels/webPanelServer.ts | 2 +- .../interactive-common/interactiveBase.ts | 22 +- .../interactiveWindowTypes.ts | 4 +- .../interactive-common/synchronization.ts | 1 + .../ipywidgets/ipyWidgetMessageDispatcher.ts | 3 + .../datascience/jupyter/jupyterNotebook.ts | 18 +- src/datascience-ui/history-react/index.html | 1 + .../history-react/redux/reducers/index.ts | 3 +- .../interactive-common/cellOutput.tsx | 2 +- .../redux/reducers/commonEffects.ts | 75 +- .../redux/reducers/transfer.ts | 15 + src/datascience-ui/ipywidgets/container.tsx | 2 + src/datascience-ui/ipywidgets/kernel.ts | 24 + src/datascience-ui/native-editor/index.html | 1 + .../native-editor/redux/reducers/index.ts | 3 +- src/ipywidgets/src/index.ts | 3 + src/ipywidgets/src/manager.ts | 2 +- .../interactiveWindow.functional.test.tsx | 2179 +++++++++-------- src/test/datascience/uiTests/helpers.ts | 2 +- 23 files changed, 1268 insertions(+), 1103 deletions(-) create mode 100644 news/2 Fixes/10873.md diff --git a/.prettierrc.js b/.prettierrc.js index c5533524995..e584661edd3 100644 --- a/.prettierrc.js +++ b/.prettierrc.js @@ -2,6 +2,7 @@ module.exports = { singleQuote: true, printWidth: 120, tabWidth: 4, + endOfLine: 'auto', trailingComma: 'none', overrides: [ { diff --git a/news/2 Fixes/10873.md b/news/2 Fixes/10873.md new file mode 100644 index 00000000000..f3cec9252c8 --- /dev/null +++ b/news/2 Fixes/10873.md @@ -0,0 +1 @@ +Handle display.update inside of cells. \ No newline at end of file diff --git a/package.datascience-ui.dependencies.json b/package.datascience-ui.dependencies.json index 73d45e1533c..240ae527cf3 100644 --- a/package.datascience-ui.dependencies.json +++ b/package.datascience-ui.dependencies.json @@ -34,6 +34,7 @@ "bail", "base16", "bintrees", + "bootstrap", "bootstrap-less", "base64-js", "create-react-context", diff --git a/src/client/common/application/webPanels/webPanel.ts b/src/client/common/application/webPanels/webPanel.ts index 8e9a7f1f265..7d43112e8ba 100644 --- a/src/client/common/application/webPanels/webPanel.ts +++ b/src/client/common/application/webPanels/webPanel.ts @@ -159,9 +159,9 @@ export class WebPanel implements IWebPanel { }; default-src 'unsafe-inline' 'unsafe-eval' vscode-resource: data: https: http: blob:;"> - React App + VS Code Python React UI - +
@@ -197,7 +197,7 @@ export class WebPanel implements IWebPanel { - React App + VS Code Python React UI diff --git a/src/client/common/application/webPanels/webPanelServer.ts b/src/client/common/application/webPanels/webPanelServer.ts index 660478add61..9b09c144b47 100644 --- a/src/client/common/application/webPanels/webPanelServer.ts +++ b/src/client/common/application/webPanels/webPanelServer.ts @@ -142,7 +142,7 @@ export class WebPanelServer { - React App + VS Code Python React UI diff --git a/src/client/datascience/interactive-common/interactiveBase.ts b/src/client/datascience/interactive-common/interactiveBase.ts index f69715b0ba3..310ad587be3 100644 --- a/src/client/datascience/interactive-common/interactiveBase.ts +++ b/src/client/datascience/interactive-common/interactiveBase.ts @@ -4,6 +4,7 @@ import '../../common/extensions'; import { nbformat } from '@jupyterlab/coreutils'; +import type { KernelMessage } from '@jupyterlab/services'; import { injectable, unmanaged } from 'inversify'; import * as os from 'os'; import * as path from 'path'; @@ -1068,7 +1069,7 @@ export abstract class InteractiveBase extends WebViewHost { + private async listenToNotebookEvents(notebook: INotebook): Promise { const statusChangeHandler = async (status: ServerStatus) => { const kernelSpec = notebook.getKernelSpec(); @@ -1087,6 +1088,9 @@ export abstract class InteractiveBase extends WebViewHost { @@ -1108,7 +1112,7 @@ export abstract class InteractiveBase extends WebViewHost & Messa [InteractiveWindowMessages.UpdateCell]: MessageType.syncAcrossSameNotebooks | MessageType.syncWithLiveShare, [InteractiveWindowMessages.UpdateModel]: MessageType.syncAcrossSameNotebooks | MessageType.syncWithLiveShare, [InteractiveWindowMessages.UpdateKernel]: MessageType.syncAcrossSameNotebooks | MessageType.syncWithLiveShare, + [InteractiveWindowMessages.UpdateDisplayData]: MessageType.syncWithLiveShare, [InteractiveWindowMessages.VariableExplorerToggle]: MessageType.other, [InteractiveWindowMessages.VariablesComplete]: MessageType.other, // Types from CssMessages diff --git a/src/client/datascience/ipywidgets/ipyWidgetMessageDispatcher.ts b/src/client/datascience/ipywidgets/ipyWidgetMessageDispatcher.ts index 7cdd275f895..7e51eaae9d1 100644 --- a/src/client/datascience/ipywidgets/ipyWidgetMessageDispatcher.ts +++ b/src/client/datascience/ipywidgets/ipyWidgetMessageDispatcher.ts @@ -4,8 +4,10 @@ 'use strict'; import { Kernel, KernelMessage } from '@jupyterlab/services'; +import * as util from 'util'; import * as uuid from 'uuid/v4'; import { Event, EventEmitter, Uri } from 'vscode'; +import { traceInfo } from '../../common/logger'; import { IDisposable } from '../../common/types'; import { createDeferred, Deferred } from '../../common/utils/async'; import { IInteractiveWindowMapping, IPyWidgetMessages } from '../interactive-common/interactiveWindowTypes'; @@ -45,6 +47,7 @@ export class IPyWidgetMessageDispatcher implements IIPyWidgetMessageDispatcher { } public receiveMessage(message: IPyWidgetMessage): void { + traceInfo(`IPyWidgetMessage: ${util.inspect(message)}`); switch (message.message) { case IPyWidgetMessages.IPyWidgets_ShellSend: this.sendIPythonShellMsg(message.payload); diff --git a/src/client/datascience/jupyter/jupyterNotebook.ts b/src/client/datascience/jupyter/jupyterNotebook.ts index eb29d23b3de..c02e7fcf585 100644 --- a/src/client/datascience/jupyter/jupyterNotebook.ts +++ b/src/client/datascience/jupyter/jupyterNotebook.ts @@ -830,7 +830,7 @@ export class JupyterNotebookBase implements INotebook { allow_stdin: true, // Allow when silent too in case runStartupCommands asks for a password store_history: !silent // Silent actually means don't output anything. Store_history is what affects execution_count }, - true + silent // Dispose only silent futures. Otherwise update_display_data doesn't finda future for a previous cell. ) : undefined; } catch (exc) { @@ -1183,6 +1183,8 @@ export class JupyterNotebookBase implements INotebook { output_type: 'execute_result', data: msg.content.data, metadata: msg.content.metadata, + // tslint:disable-next-line: no-any + transient: msg.content.transient as any, // NOSONAR execution_count: msg.content.execution_count }, clearState @@ -1284,19 +1286,15 @@ export class JupyterNotebookBase implements INotebook { const output: nbformat.IDisplayData = { output_type: 'display_data', data: msg.content.data, - metadata: msg.content.metadata + metadata: msg.content.metadata, + // tslint:disable-next-line: no-any + transient: msg.content.transient as any // NOSONAR }; this.addToCellData(cell, output, clearState); } - private handleUpdateDisplayData(msg: KernelMessage.IUpdateDisplayDataMsg, _clearState: RefBool, cell: ICell) { - // Should already have a display data output in our cell. - const data: nbformat.ICodeCell = cell.data as nbformat.ICodeCell; - const output = data.outputs.find((o) => o.output_type === 'display_data'); - if (output) { - output.data = msg.content.data; - output.metadata = msg.content.metadata; - } + private handleUpdateDisplayData(_msg: KernelMessage.IUpdateDisplayDataMsg, _clearState: RefBool, _cell: ICell) { + // Updates should be handled outside. } private handleClearOutput(msg: KernelMessage.IClearOutputMsg, clearState: RefBool, cell: ICell) { diff --git a/src/datascience-ui/history-react/index.html b/src/datascience-ui/history-react/index.html index d7e9ddf7ee6..5f8c85aee90 100644 --- a/src/datascience-ui/history-react/index.html +++ b/src/datascience-ui/history-react/index.html @@ -5,6 +5,7 @@ React App +