From 63dd610b8687c0f31b052659f98ae75ca2694898 Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Fri, 10 Apr 2020 14:29:04 -0700 Subject: [PATCH] Support workspace images in markdown cells --- news/2 Fixes/11040.md | 1 + src/client/common/application/types.ts | 5 +++++ src/client/common/application/webPanels/webPanelProvider.ts | 3 +++ src/client/datascience/webViewHost.ts | 5 ++++- 4 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 news/2 Fixes/11040.md diff --git a/news/2 Fixes/11040.md b/news/2 Fixes/11040.md new file mode 100644 index 000000000000..128c8adde13b --- /dev/null +++ b/news/2 Fixes/11040.md @@ -0,0 +1 @@ +Ensure images in workspace folder are supported within markdown cells in a `Notebook`. diff --git a/src/client/common/application/types.ts b/src/client/common/application/types.ts index c942eba09151..2069d3c616f0 100644 --- a/src/client/common/application/types.ts +++ b/src/client/common/application/types.ts @@ -1094,6 +1094,11 @@ export interface IWebPanelOptions { listener: IWebPanelMessageListener; title: string; rootPath: string; + /** + * Additional paths apart from cwd and rootPath, that webview would allow loading resources/files from. + * E.g. required for webview to serve images from worksapces when nb is in a nested folder. + */ + additionalPaths?: string[]; scripts: string[]; startHttpServer: boolean; cwd: string; diff --git a/src/client/common/application/webPanels/webPanelProvider.ts b/src/client/common/application/webPanels/webPanelProvider.ts index ac57b7369965..d75de8450500 100644 --- a/src/client/common/application/webPanels/webPanelProvider.ts +++ b/src/client/common/application/webPanels/webPanelProvider.ts @@ -30,6 +30,9 @@ export class WebPanelProvider implements IWebPanelProvider { // Allow loading resources from the `/tmp` folder when in webiviews. // Used by widgets to place files that are not otherwise accessible. const additionalRootPaths = [Uri.file(path.join(this.context.extensionPath, 'tmp'))]; + if (Array.isArray(options.additionalPaths)) { + additionalRootPaths.push(...options.additionalPaths.map((item) => Uri.file(item))); + } return new WebPanel( this.fs, this.disposableRegistry, diff --git a/src/client/datascience/webViewHost.ts b/src/client/datascience/webViewHost.ts index aa96f5e9be45..a4bd0bc4622f 100644 --- a/src/client/datascience/webViewHost.ts +++ b/src/client/datascience/webViewHost.ts @@ -256,6 +256,8 @@ export abstract class WebViewHost implements IDisposable { traceWarning(`startHttpServer=${startHttpServer}, will not be used. Temporarily turned off`); + const workspaceFolder = this.workspaceService.getWorkspaceFolder(Uri.file(cwd))?.uri; + // Use this script to create our web view panel. It should contain all of the necessary // script to communicate with this class. this.webPanel = await this.provider.create({ @@ -267,7 +269,8 @@ export abstract class WebViewHost implements IDisposable { settings, startHttpServer: false, cwd, - webViewPanel + webViewPanel, + additionalPaths: workspaceFolder ? [workspaceFolder.fsPath] : [] }); traceInfo('Web view created.');