Skip to content

Commit 6eeb225

Browse files
authored
Remove createRawHtml output method for notebook renderers (#7246)
1 parent c90f4df commit 6eeb225

File tree

3 files changed

+2
-131
lines changed

3 files changed

+2
-131
lines changed

src/vs/workbench/contrib/positronOutputWebview/browser/notebookOutputWebviewService.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,5 @@ export interface IPositronNotebookOutputWebviewService {
7777
viewType?: string;
7878
}): Promise<INotebookOutputWebview | undefined>;
7979

80-
/**
81-
* Create a new raw HTML output webview.
82-
*
83-
* @param opts The options for the webview
84-
* @param opts.id A unique ID for this webview; typically the ID of the message
85-
* that created it.
86-
* @param opts.runtimeOrSessionId The runtime that owns this webview. Can also be a string of the ID of the runtime.
87-
* @param opts.html The HTML content to render in the webview.
88-
* @returns A promise that resolves to the new webview of the desired type.
89-
*/
90-
createRawHtmlOutput(opts: {
91-
id: string;
92-
html: string;
93-
runtimeOrSessionId: ILanguageRuntimeSession | string;
94-
}): Promise<INotebookOutputWebview>;
9580
}
9681

src/vs/workbench/contrib/positronOutputWebview/browser/notebookOutputWebviewServiceImpl.ts

Lines changed: 0 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@ import { NotebookOutputWebview } from './notebookOutputWebview.js';
1616
import { INotebookOutputWebview, IPositronNotebookOutputWebviewService } from './notebookOutputWebviewService.js';
1717
import { IWebviewService, WebviewInitInfo } from '../../webview/browser/webview.js';
1818
import { asWebviewUri } from '../../webview/common/webview.js';
19-
import { IExtensionService } from '../../../services/extensions/common/extensions.js';
2019
import { ILanguageRuntimeMessageWebOutput } from '../../../services/languageRuntime/common/languageRuntimeService.js';
2120
import { ILanguageRuntimeSession } from '../../../services/runtimeSession/common/runtimeSessionService.js';
2221
import { dirname } from '../../../../base/common/resources.js';
2322
import { INotebookRendererMessagingService } from '../../notebook/common/notebookRendererMessagingService.js';
2423
import { ILogService } from '../../../../platform/log/common/log.js';
25-
import { handleWebviewLinkClicksInjection } from './downloadUtils.js';
2624
import { IInstantiationService } from '../../../../platform/instantiation/common/instantiation.js';
2725
import { webviewMessageCodeString } from '../../positronWebviewPreloads/browser/notebookOutputUtils.js';
2826

@@ -45,7 +43,6 @@ export class PositronNotebookOutputWebviewService implements IPositronNotebookOu
4543
@IWebviewService private readonly _webviewService: IWebviewService,
4644
@INotebookService private readonly _notebookService: INotebookService,
4745
@IWorkspaceTrustManagementService private readonly _workspaceTrustManagementService: IWorkspaceTrustManagementService,
48-
@IExtensionService private readonly _extensionService: IExtensionService,
4946
@INotebookRendererMessagingService private readonly _notebookRendererMessagingService: INotebookRendererMessagingService,
5047
@ILogService private _logService: ILogService,
5148
@IInstantiationService private readonly _instantiationService: IInstantiationService
@@ -147,7 +144,6 @@ export class PositronNotebookOutputWebviewService implements IPositronNotebookOu
147144
for (const mimeType of Object.keys(output.data)) {
148145
// Don't use a renderer for non-widget MIME types
149146
if (mimeType === 'text/plain' ||
150-
mimeType === 'text/html' ||
151147
mimeType === 'image/png') {
152148
continue;
153149
}
@@ -163,18 +159,6 @@ export class PositronNotebookOutputWebviewService implements IPositronNotebookOu
163159
}
164160
}
165161

166-
// If no dedicated renderer is found, check to see if there is a raw
167-
// HTML representation of the output.
168-
for (const mimeType of Object.keys(output.data)) {
169-
if (mimeType === 'text/html') {
170-
return this.createRawHtmlOutput({
171-
id,
172-
runtimeOrSessionId: runtime,
173-
html: output.data[mimeType],
174-
});
175-
}
176-
}
177-
178162
// No renderer found
179163
return Promise.resolve(undefined);
180164
}
@@ -394,70 +378,6 @@ export class PositronNotebookOutputWebviewService implements IPositronNotebookOu
394378
return notebookOutputWebview;
395379
}
396380

397-
async createRawHtmlOutput({ id, html, runtimeOrSessionId }: {
398-
id: string;
399-
html: string;
400-
runtimeOrSessionId: ILanguageRuntimeSession | string;
401-
}): Promise<INotebookOutputWebview> {
402-
403-
// Load the Jupyter extension. Many notebook HTML outputs have a dependency on jQuery,
404-
// which is provided by the Jupyter extension.
405-
const jupyterExtension = await this._extensionService.getExtension('ms-toolsai.jupyter');
406-
if (!jupyterExtension) {
407-
return Promise.reject(`Jupyter extension 'ms-toolsai.jupyter' not found`);
408-
}
409-
410-
// Create the metadata for the webview
411-
const webviewInitInfo: WebviewInitInfo = {
412-
// Use the active window's origin. All webviews with the same origin will reuse the same
413-
// service worker.
414-
origin: DOM.getActiveWindow().origin,
415-
contentOptions: {
416-
allowScripts: true,
417-
localResourceRoots: [jupyterExtension.extensionLocation]
418-
},
419-
options: {},
420-
title: '',
421-
// Sometimes we don't have an active runtime (e.g. rendering html for a notebook pre
422-
// runtime start) so we can't get the extension id from the runtime.
423-
extension: typeof runtimeOrSessionId === 'string' ? undefined : { id: runtimeOrSessionId.runtimeMetadata.extensionId }
424-
};
425-
426-
const webview = this._webviewService.createWebviewOverlay(webviewInitInfo);
427-
428-
// Form the path to the jQuery library and inject it into the HTML
429-
const jQueryPath = asWebviewUri(
430-
jupyterExtension.extensionLocation.with({
431-
path: jupyterExtension.extensionLocation.path +
432-
'/out/node_modules/jquery/dist/jquery.min.js'
433-
}));
434-
435-
webview.setHtml(`
436-
<script src='${jQueryPath}'></script>
437-
${PositronNotebookOutputWebviewService.CssAddons}
438-
${html}
439-
<script>
440-
const vscode = acquireVsCodeApi();
441-
window.onload = function() {
442-
vscode.postMessage({
443-
__vscode_notebook_message: true,
444-
type: 'positronRenderComplete',
445-
});
446-
447-
${handleWebviewLinkClicksInjection};
448-
};
449-
</script>`);
450-
451-
return this._instantiationService.createInstance(
452-
NotebookOutputWebview,
453-
{
454-
id,
455-
sessionId: typeof runtimeOrSessionId === 'string' ? runtimeOrSessionId : runtimeOrSessionId.sessionId,
456-
webview
457-
}
458-
);
459-
}
460-
461381
/**
462382
* A set of CSS addons to inject into the HTML of the webview. Used to do things like
463383
* hide elements that are not functional in the context of positron such as links to

src/vs/workbench/contrib/positronWebviewPreloads/browser/positronWebviewPreloadsService.ts

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import { UiFrontendEvent } from '../../../services/languageRuntime/common/positr
1515
import { VSBuffer } from '../../../../base/common/buffer.js';
1616
import { isWebviewDisplayMessage, isWebviewReplayMessage } from './utils.js';
1717
import { IPositronNotebookInstance } from '../../../services/positronNotebook/browser/IPositronNotebookInstance.js';
18-
import { buildWebviewHTML, webviewMessageCodeString } from './notebookOutputUtils.js';
1918

2019
/**
2120
* Format of output from a notebook cell
@@ -153,17 +152,15 @@ export class PositronWebviewPreloadService extends Disposable implements IPositr
153152
* @param outputs Array of output objects containing mime types to check
154153
* @returns The type of webview message ('display', 'preload') or null if not handled
155154
*/
156-
static getWebviewMessageType(outputs: { mime: string }[]): NotebookPreloadOutputResults['preloadMessageType'] | 'html' | null {
155+
static getWebviewMessageType(outputs: { mime: string }[]): NotebookPreloadOutputResults['preloadMessageType'] | null {
157156
const mimeTypes = outputs.map(output => output.mime);
158157
if (isWebviewDisplayMessage(mimeTypes)) {
159158
return 'display';
160159
}
161160
if (isWebviewReplayMessage(mimeTypes)) {
162161
return 'preload';
163162
}
164-
if (mimeTypes.includes('text/html')) {
165-
return 'html';
166-
}
163+
167164
return null;
168165
}
169166

@@ -209,42 +206,11 @@ export class PositronWebviewPreloadService extends Disposable implements IPositr
209206
};
210207
}
211208

212-
// We also want to send plain (non preload reliant) html messages to output.
213-
if (messageType === 'html') {
214-
return {
215-
preloadMessageType: 'display',
216-
webview: this._handleHtmlOutput(instance, outputId, outputs)
217-
};
218-
}
219-
220209
// Preload messages contain setup code or dependencies that need to be stored
221210
// for future webviews but don't need to be displayed themselves
222211
notebookMessages.push(runtimeOutput);
223212
return { preloadMessageType: messageType };
224213
}
225-
226-
/**
227-
* Create a webview for a plain html output.
228-
*/
229-
private async _handleHtmlOutput(instance: IPositronNotebookInstance, outputId: NotebookOutput['outputId'], outputs: NotebookOutput['outputs']) {
230-
231-
// Get the output with mime type of html
232-
const htmlOutput = outputs.find(output => output.mime === 'text/html');
233-
if (!htmlOutput) {
234-
throw new Error('Expected HTML output');
235-
}
236-
237-
const notebookWebview = await this._notebookOutputWebviewService.createRawHtmlOutput({
238-
id: outputId,
239-
runtimeOrSessionId: instance.id,
240-
html: buildWebviewHTML({
241-
content: htmlOutput.data.toString(),
242-
script: webviewMessageCodeString,
243-
})
244-
});
245-
246-
return notebookWebview;
247-
}
248214
/**
249215
* Create a plot client for a display message by replaying all the associated previous messages.
250216
* Alerts the plots pane that a new plot is ready.

0 commit comments

Comments
 (0)