Skip to content

Commit

Permalink
Add optional localResourceRoots to static preloads contribution
Browse files Browse the repository at this point in the history
  • Loading branch information
mjbvz committed May 16, 2023
1 parent 89f8e22 commit c80c1dc
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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.'),
},
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ export class NotebookService extends Disposable implements INotebookService {
type,
extension: extension.description,
entrypoint: notebookContribution.entrypoint,
localResourceRoots: notebookContribution.localResourceRoots ?? [],
}));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1084,7 +1084,10 @@ export class BackLayerWebView<T extends ICommonCellInfo> 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()
Expand Down
1 change: 1 addition & 0 deletions src/vs/workbench/contrib/notebook/common/notebookCommon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ export interface INotebookStaticPreloadInfo {
readonly type: string;
readonly entrypoint: URI;
readonly extensionLocation: URI;
readonly localResourceRoots: readonly URI[];
}

export interface IOrderedMimeType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

0 comments on commit c80c1dc

Please sign in to comment.