diff --git a/code/changes/896.fix.md b/code/changes/896.fix.md new file mode 100644 index 000000000..9776e8389 --- /dev/null +++ b/code/changes/896.fix.md @@ -0,0 +1 @@ +The preview window should now work when using Codespaces diff --git a/code/src/node/preview.ts b/code/src/node/preview.ts index 4f718ebd1..b5c8e84d9 100644 --- a/code/src/node/preview.ts +++ b/code/src/node/preview.ts @@ -141,7 +141,21 @@ export class PreviewManager { return } - this.panel.webview.postMessage({ 'show': params.uri }) + let panel = this.panel + let uri = vscode.Uri.parse(params.uri) + + // Needed so that previews work in Codespaces + // see: https://github.com/swyddfa/esbonio/issues/896 + vscode.env.asExternalUri(uri).then( + extUri => { + this.logger.debug(`${uri.toString(true)} -> asExternalUri -> ${extUri.toString(true)}`) + panel.webview.postMessage({ 'show': extUri.toString(true) }) + }, + err => { + this.logger.error(`Unable to convert uri to an external uri: ${err}`) + } + ) + } private showInternalDocument(params: ShowDocumentParams) {