Skip to content

Commit

Permalink
Log webview paths in placeholders
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Yu committed Feb 14, 2024
1 parent 9556280 commit e161c10
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/utils/webview.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
import * as vscode from 'vscode'
import { lw } from '../lw'

const logger = lw.log('Util', 'Webview')

let pathLogged = false
export function replaceWebviewPlaceholders(content: string, webview: vscode.Webview): string {
const extensionRootUri = vscode.Uri.file(lw.extensionRoot)
const resourcesFolderUri = webview.asWebviewUri(vscode.Uri.joinPath(extensionRootUri, 'resources'))
const resourcesFolderLink = resourcesFolderUri.toString()
const pdfjsDistUri = webview.asWebviewUri(vscode.Uri.joinPath(extensionRootUri, 'node_modules', 'pdfjs-dist'))
const pdfjsDistLink = pdfjsDistUri.toString()
if (!pathLogged) {
pathLogged = true
logger.log(`%VSCODE_RES% = ${resourcesFolderLink} .`)
logger.log(`%VSCODE_PDFJS_DIST% = ${pdfjsDistLink} .`)
logger.log(`%VSCODE_CSP% = ${webview.cspSource} .`)
}
return content.replace(/%VSCODE_RES%/g, resourcesFolderLink)
.replace(/%VSCODE_PDFJS_DIST%/g, pdfjsDistLink)
.replace(/%VSCODE_CSP%/g, webview.cspSource)
Expand Down

0 comments on commit e161c10

Please sign in to comment.