11'use strict' ;
2- import * as paths from 'path' ;
3- import * as fs from 'fs' ;
2+ import { TextDecoder } from 'util' ;
43import {
54 commands ,
65 ConfigurationChangeEvent ,
@@ -194,32 +193,13 @@ export abstract class WebviewBase implements Disposable {
194193 }
195194 }
196195
197- private _html : string | undefined ;
198196 private async getHtml ( webview : Webview ) : Promise < string > {
199- const filename = Container . context . asAbsolutePath ( paths . join ( 'dist/webviews/' , this . filename ) ) ;
200-
201- let content ;
202- // When we are debugging avoid any caching so that we can change the html and have it update without reloading
203- if ( Logger . isDebugging ) {
204- content = await new Promise < string > ( ( resolve , reject ) => {
205- fs . readFile ( filename , 'utf8' , ( err , data ) => {
206- if ( err ) {
207- reject ( err ) ;
208- } else {
209- resolve ( data ) ;
210- }
211- } ) ;
212- } ) ;
213- } else {
214- if ( this . _html != null ) return this . _html ;
215-
216- const doc = await workspace . openTextDocument ( filename ) ;
217- content = doc . getText ( ) ;
218- }
197+ const uri = Uri . joinPath ( Container . context . extensionUri , 'dist' , 'webviews' , this . filename ) ;
198+ const content = new TextDecoder ( 'utf8' ) . decode ( await workspace . fs . readFile ( uri ) ) ;
219199
220200 let html = content
221201 . replace ( / # { cspSource} / g, webview . cspSource )
222- . replace ( / # { root} / g, webview . asWebviewUri ( Uri . file ( Container . context . asAbsolutePath ( '.' ) ) ) . toString ( ) ) ;
202+ . replace ( / # { root} / g, webview . asWebviewUri ( Container . context . extensionUri ) . toString ( ) ) ;
223203
224204 if ( this . renderHead ) {
225205 html = html . replace ( / # { head} / i, await this . renderHead ( ) ) ;
@@ -233,7 +213,6 @@ export abstract class WebviewBase implements Disposable {
233213 html = html . replace ( / # { endOfBody} / i, await this . renderEndOfBody ( ) ) ;
234214 }
235215
236- this . _html = html ;
237216 return html ;
238217 }
239218
0 commit comments