From c80c1dc0ce94087d7f7f2d8fc8dc264d77b78350 Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Tue, 16 May 2023 11:13:14 -0700 Subject: [PATCH] Add optional localResourceRoots to static preloads contribution Fixes #175033 --- .../contrib/notebook/browser/notebookExtensionPoint.ts | 7 +++++++ .../notebook/browser/services/notebookServiceImpl.ts | 1 + .../notebook/browser/view/renderers/backLayerWebView.ts | 5 ++++- src/vs/workbench/contrib/notebook/common/notebookCommon.ts | 1 + .../contrib/notebook/common/notebookOutputRenderer.ts | 3 +++ 5 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/vs/workbench/contrib/notebook/browser/notebookExtensionPoint.ts b/src/vs/workbench/contrib/notebook/browser/notebookExtensionPoint.ts index 4f285ddac022e..026f2bb14b2da 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebookExtensionPoint.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebookExtensionPoint.ts @@ -45,11 +45,13 @@ export interface INotebookRendererContribution { const NotebookPreloadContribution = Object.freeze({ type: 'type', entrypoint: 'entrypoint', + localResourceRoots: 'localResourceRoots', }); interface INotebookPreloadContribution { readonly [NotebookPreloadContribution.type]: string; readonly [NotebookPreloadContribution.entrypoint]: string; + readonly [NotebookPreloadContribution.localResourceRoots]: readonly string[]; } const notebookProviderContribution: IJSONSchema = { @@ -226,6 +228,11 @@ const notebookPreloadContribution: IJSONSchema = { type: 'string', description: nls.localize('contributes.preload.entrypoint', 'Path to file loaded in the webview.'), }, + [NotebookPreloadContribution.localResourceRoots]: { + type: 'array', + items: { type: 'string' }, + description: nls.localize('contributes.preload.localResourceRoots', 'Paths to additional resources that should be allowed in the webview.'), + }, } } }; diff --git a/src/vs/workbench/contrib/notebook/browser/services/notebookServiceImpl.ts b/src/vs/workbench/contrib/notebook/browser/services/notebookServiceImpl.ts index 3caf3c449a86b..0de5d615338b1 100644 --- a/src/vs/workbench/contrib/notebook/browser/services/notebookServiceImpl.ts +++ b/src/vs/workbench/contrib/notebook/browser/services/notebookServiceImpl.ts @@ -529,6 +529,7 @@ export class NotebookService extends Disposable implements INotebookService { type, extension: extension.description, entrypoint: notebookContribution.entrypoint, + localResourceRoots: notebookContribution.localResourceRoots ?? [], })); } } diff --git a/src/vs/workbench/contrib/notebook/browser/view/renderers/backLayerWebView.ts b/src/vs/workbench/contrib/notebook/browser/view/renderers/backLayerWebView.ts index e1dce4ece164c..d2712dea5f82b 100644 --- a/src/vs/workbench/contrib/notebook/browser/view/renderers/backLayerWebView.ts +++ b/src/vs/workbench/contrib/notebook/browser/view/renderers/backLayerWebView.ts @@ -1084,7 +1084,10 @@ export class BackLayerWebView extends Themable { return [ this.notebookService.getNotebookProviderResourceRoots(), this.notebookService.getRenderers().map(x => dirname(x.entrypoint.path)), - Array.from(this.notebookService.getStaticPreloads(this.notebookViewType), x => dirname(x.entrypoint)), + ...Array.from(this.notebookService.getStaticPreloads(this.notebookViewType), x => [ + dirname(x.entrypoint), + ...x.localResourceRoots, + ]), workspaceFolders, notebookDir, this.getBuiltinLocalResourceRoots() diff --git a/src/vs/workbench/contrib/notebook/common/notebookCommon.ts b/src/vs/workbench/contrib/notebook/common/notebookCommon.ts index 076610d68a4ca..9c6a84e21b164 100644 --- a/src/vs/workbench/contrib/notebook/common/notebookCommon.ts +++ b/src/vs/workbench/contrib/notebook/common/notebookCommon.ts @@ -189,6 +189,7 @@ export interface INotebookStaticPreloadInfo { readonly type: string; readonly entrypoint: URI; readonly extensionLocation: URI; + readonly localResourceRoots: readonly URI[]; } export interface IOrderedMimeType { diff --git a/src/vs/workbench/contrib/notebook/common/notebookOutputRenderer.ts b/src/vs/workbench/contrib/notebook/common/notebookOutputRenderer.ts index 8400da97fa0c8..404e84c910d8d 100644 --- a/src/vs/workbench/contrib/notebook/common/notebookOutputRenderer.ts +++ b/src/vs/workbench/contrib/notebook/common/notebookOutputRenderer.ts @@ -124,15 +124,18 @@ export class NotebookStaticPreloadInfo implements INotebookStaticPreloadInfo { readonly type: string; readonly entrypoint: URI; readonly extensionLocation: URI; + readonly localResourceRoots: readonly URI[]; constructor(descriptor: { readonly type: string; readonly entrypoint: string; + readonly localResourceRoots: readonly string[]; readonly extension: IExtensionDescription; }) { this.type = descriptor.type; this.entrypoint = joinPath(descriptor.extension.extensionLocation, descriptor.entrypoint); this.extensionLocation = descriptor.extension.extensionLocation; + this.localResourceRoots = descriptor.localResourceRoots.map(root => joinPath(descriptor.extension.extensionLocation, root)); } }