Skip to content

Commit 8ac8da2

Browse files
authored
Use VSC API instead of hardcoding the uri resource vscode-resource (microsoft#7835)
* Update vscode dependency * News entry * Stop hardcoding 'vscode-resource' and use VSC api
1 parent 0e24bcf commit 8ac8da2

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

news/3 Code Health/7834.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Use `Webview.asWebviewUri` to generate a URI for use in the `Webview Panel` instead of hardcoding the resource `vscode-resource`.

src/client/common/application/webPanel.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import '../../common/extensions';
55

66
import * as fs from 'fs-extra';
77
import * as path from 'path';
8-
import { Uri, ViewColumn, WebviewPanel, window } from 'vscode';
9-
8+
import { Uri, ViewColumn, Webview, WebviewPanel, window } from 'vscode';
109
import * as localize from '../../common/utils/localize';
1110
import { Identifiers } from '../../datascience/constants';
1211
import { IServiceContainer } from '../../ioc/types';
@@ -89,7 +88,7 @@ export class WebPanel implements IWebPanel {
8988

9089
// Call our special function that sticks this script inside of an html page
9190
// and translates all of the paths to vscode-resource URIs
92-
this.panel.webview.html = this.generateReactHtml(mainScriptPath, embeddedCss, settings);
91+
this.panel.webview.html = this.generateReactHtml(mainScriptPath, this.panel.webview, embeddedCss, settings);
9392

9493
// Reset when the current panel is closed
9594
this.disposableRegistry.push(this.panel.onDidDispose(() => {
@@ -118,11 +117,9 @@ export class WebPanel implements IWebPanel {
118117
}
119118

120119
// tslint:disable-next-line:no-any
121-
private generateReactHtml(mainScriptPath: string, embeddedCss?: string, settings?: any) {
122-
const uriBasePath = Uri.file(`${path.dirname(mainScriptPath)}/`);
123-
const uriPath = Uri.file(mainScriptPath);
124-
const uriBase = uriBasePath.with({ scheme: 'vscode-resource' });
125-
const uri = uriPath.with({ scheme: 'vscode-resource' });
120+
private generateReactHtml(mainScriptPath: string, webView: Webview, embeddedCss?: string, settings?: any) {
121+
const uriBase = webView.asWebviewUri(Uri.file(`${path.dirname(mainScriptPath)}/`));
122+
const uri = webView.asWebviewUri(Uri.file(mainScriptPath));
126123
const locDatabase = localize.getCollectionJSON();
127124
const style = embeddedCss ? embeddedCss : '';
128125
const settingsString = settings ? JSON.stringify(settings) : '{}';

0 commit comments

Comments
 (0)