未验证 提交 207fece6 编写于 作者: M Matt Bierner

Revert "Remove Jupyter specific loader special case (#126939)"

This reverts commit efe0678e.

Fixes #132557
上级 b498b7d2
...@@ -382,7 +382,7 @@ export class NotebookTextDiffEditor extends EditorPane implements INotebookTextD ...@@ -382,7 +382,7 @@ export class NotebookTextDiffEditor extends EditorPane implements INotebookTextD
this._modifiedWebview = this.instantiationService.createInstance(BackLayerWebView, this, id, resource, this._notebookOptions.computeDiffWebviewOptions(), undefined) as BackLayerWebView<IDiffCellInfo>; this._modifiedWebview = this.instantiationService.createInstance(BackLayerWebView, this, id, resource, this._notebookOptions.computeDiffWebviewOptions(), undefined) as BackLayerWebView<IDiffCellInfo>;
// attach the webview container to the DOM tree first // attach the webview container to the DOM tree first
this._list.rowsContainer.insertAdjacentElement('afterbegin', this._modifiedWebview.element); this._list.rowsContainer.insertAdjacentElement('afterbegin', this._modifiedWebview.element);
this._modifiedWebview.createWebview(); await this._modifiedWebview.createWebview();
this._modifiedWebview.element.style.width = `calc(50% - 16px)`; this._modifiedWebview.element.style.width = `calc(50% - 16px)`;
this._modifiedWebview.element.style.left = `calc(50%)`; this._modifiedWebview.element.style.left = `calc(50%)`;
} }
...@@ -395,7 +395,7 @@ export class NotebookTextDiffEditor extends EditorPane implements INotebookTextD ...@@ -395,7 +395,7 @@ export class NotebookTextDiffEditor extends EditorPane implements INotebookTextD
this._originalWebview = this.instantiationService.createInstance(BackLayerWebView, this, id, resource, this._notebookOptions.computeDiffWebviewOptions(), undefined) as BackLayerWebView<IDiffCellInfo>; this._originalWebview = this.instantiationService.createInstance(BackLayerWebView, this, id, resource, this._notebookOptions.computeDiffWebviewOptions(), undefined) as BackLayerWebView<IDiffCellInfo>;
// attach the webview container to the DOM tree first // attach the webview container to the DOM tree first
this._list.rowsContainer.insertAdjacentElement('afterbegin', this._originalWebview.element); this._list.rowsContainer.insertAdjacentElement('afterbegin', this._originalWebview.element);
this._originalWebview.createWebview(); await this._originalWebview.createWebview();
this._originalWebview.element.style.width = `calc(50% - 16px)`; this._originalWebview.element.style.width = `calc(50% - 16px)`;
this._originalWebview.element.style.left = `16px`; this._originalWebview.element.style.left = `16px`;
} }
......
...@@ -1233,7 +1233,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD ...@@ -1233,7 +1233,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD
throw new Error('Notebook output webview object is not created successfully.'); throw new Error('Notebook output webview object is not created successfully.');
} }
this._webview.createWebview(); await this._webview.createWebview();
if (!this._webview.webview) { if (!this._webview.webview) {
throw new Error('Notebook output webview element was not created successfully.'); throw new Error('Notebook output webview element was not created successfully.');
} }
......
...@@ -10,8 +10,8 @@ import { VSBuffer } from 'vs/base/common/buffer'; ...@@ -10,8 +10,8 @@ import { VSBuffer } from 'vs/base/common/buffer';
import { Emitter, Event } from 'vs/base/common/event'; import { Emitter, Event } from 'vs/base/common/event';
import { Disposable } from 'vs/base/common/lifecycle'; import { Disposable } from 'vs/base/common/lifecycle';
import { getExtensionForMimeType } from 'vs/base/common/mime'; import { getExtensionForMimeType } from 'vs/base/common/mime';
import { Schemas } from 'vs/base/common/network'; import { FileAccess, Schemas } from 'vs/base/common/network';
import { isMacintosh } from 'vs/base/common/platform'; import { isMacintosh, isWeb } from 'vs/base/common/platform';
import { dirname, joinPath } from 'vs/base/common/resources'; import { dirname, joinPath } from 'vs/base/common/resources';
import { URI } from 'vs/base/common/uri'; import { URI } from 'vs/base/common/uri';
import * as UUID from 'vs/base/common/uuid'; import * as UUID from 'vs/base/common/uuid';
...@@ -96,6 +96,7 @@ export class BackLayerWebView<T extends ICommonCellInfo> extends Disposable { ...@@ -96,6 +96,7 @@ export class BackLayerWebView<T extends ICommonCellInfo> extends Disposable {
private readonly _onMessage = this._register(new Emitter<INotebookWebviewMessage>()); private readonly _onMessage = this._register(new Emitter<INotebookWebviewMessage>());
private readonly _preloadsCache = new Set<string>(); private readonly _preloadsCache = new Set<string>();
public readonly onMessage: Event<INotebookWebviewMessage> = this._onMessage.event; public readonly onMessage: Event<INotebookWebviewMessage> = this._onMessage.event;
private _initalized?: Promise<void>;
private _disposed = false; private _disposed = false;
private _currentKernel?: INotebookKernel; private _currentKernel?: INotebookKernel;
...@@ -215,7 +216,7 @@ export class BackLayerWebView<T extends ICommonCellInfo> extends Disposable { ...@@ -215,7 +216,7 @@ export class BackLayerWebView<T extends ICommonCellInfo> extends Disposable {
}; };
} }
private generateContent(baseUrl: string) { private generateContent(coreDependencies: string, baseUrl: string) {
const renderersData = this.getRendererData(); const renderersData = this.getRendererData();
const preloadScript = preloadsScriptStr( const preloadScript = preloadsScriptStr(
this.options, this.options,
...@@ -356,8 +357,13 @@ export class BackLayerWebView<T extends ICommonCellInfo> extends Disposable { ...@@ -356,8 +357,13 @@ export class BackLayerWebView<T extends ICommonCellInfo> extends Disposable {
</style> </style>
</head> </head>
<body style="overflow: hidden;"> <body style="overflow: hidden;">
<script>
self.require = {};
</script>
${coreDependencies}
<div id='container' class="widgetarea" style="position: absolute;width:100%;top: 0px"></div>
<script type="module">${preloadScript}</script>
<div id="container" class="widgetarea" style="position: absolute; width:100%; top: 0px"></div> <div id="container" class="widgetarea" style="position: absolute; width:100%; top: 0px"></div>
<script type="module" nonce="${this.nonce}">${preloadScript}</script>
</body> </body>
</html>`; </html>`;
} }
...@@ -402,13 +408,72 @@ export class BackLayerWebView<T extends ICommonCellInfo> extends Disposable { ...@@ -402,13 +408,72 @@ export class BackLayerWebView<T extends ICommonCellInfo> extends Disposable {
return !!this.webview; return !!this.webview;
} }
createWebview(): void { async createWebview(): Promise<void> {
const baseUrl = this.asWebviewUri(dirname(this.documentUri), undefined); const baseUrl = this.asWebviewUri(dirname(this.documentUri), undefined);
const htmlContent = this.generateContent(baseUrl.toString());
// Python notebooks assume that requirejs is a global.
// For all other notebooks, they need to provide their own loader.
if (!this.documentUri.path.toLowerCase().endsWith('.ipynb')) {
const htmlContent = this.generateContent('', baseUrl.toString());
this._initialize(htmlContent); this._initialize(htmlContent);
return; return;
} }
let coreDependencies = '';
let resolveFunc: () => void;
this._initalized = new Promise<void>((resolve, reject) => {
resolveFunc = resolve;
});
if (!isWeb) {
const loaderUri = FileAccess.asFileUri('vs/loader.js', require);
const loader = this.asWebviewUri(loaderUri, undefined);
coreDependencies = `<script src="${loader}"></script><script>
var requirejs = (function() {
return require;
}());
</script>`;
const htmlContent = this.generateContent(coreDependencies, baseUrl.toString());
this._initialize(htmlContent);
resolveFunc!();
} else {
const loaderUri = FileAccess.asBrowserUri('vs/loader.js', require);
fetch(loaderUri.toString(true)).then(async response => {
if (response.status !== 200) {
throw new Error(response.statusText);
}
const loaderJs = await response.text();
coreDependencies = `
<script>
${loaderJs}
</script>
<script>
var requirejs = (function() {
return require;
}());
</script>
`;
const htmlContent = this.generateContent(coreDependencies, baseUrl.toString());
this._initialize(htmlContent);
resolveFunc!();
}, error => {
// the fetch request is rejected
const htmlContent = this.generateContent(coreDependencies, baseUrl.toString());
this._initialize(htmlContent);
resolveFunc!();
});
}
await this._initalized;
}
private _initialize(content: string) { private _initialize(content: string) {
if (!document.body.contains(this.element)) { if (!document.body.contains(this.element)) {
throw new Error('Element is already detached from the DOM tree'); throw new Error('Element is already detached from the DOM tree');
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册