This repository has been archived by the owner on Nov 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use development mode, add error overlay
Fixes microsoft/vscode#95908
- Loading branch information
1 parent
a318bba
commit 0c1f613
Showing
8 changed files
with
489 additions
and
288 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,52 @@ | ||
import * as vscode from 'vscode'; | ||
import * as path from 'path'; | ||
import { viewType, renderCallback } from '../common/constants'; | ||
|
||
const onLoad = `window['${renderCallback}'] && window['${renderCallback}'](document.currentScript)`; | ||
const onLoad = `(() => { debugger; window['${renderCallback}'] && window['${renderCallback}'](document.currentScript) })()`; | ||
|
||
export class SampleRenderer implements vscode.NotebookOutputRenderer { | ||
private hasOpenedDevTools = new WeakSet<vscode.NotebookDocument>(); | ||
|
||
public readonly preloads: vscode.Uri[] = []; | ||
|
||
constructor(context: vscode.ExtensionContext) { | ||
constructor(private readonly context: vscode.ExtensionContext) { | ||
// Set preloads to a list of scripts you want VS Code to load before your | ||
// renderer is ready. Here, we load the compiled Webpack bundle in 'release' | ||
// mode and load from the webpack-dev-server in development. | ||
|
||
// todo(connor4312): https://github.com/microsoft/vscode/issues/95988 | ||
// if (process.env.RENDERER_USE_WEBPACK_SERVER && context.inDevelopment) { | ||
// this.preloads.push(vscode.Uri.parse('http://localhost:8111/index.js')); | ||
// } else { | ||
// this.preloads.push(vscode.Uri.file(path.join(context.extensionPath, 'out/client/index.js'))); | ||
// } | ||
const webpackDevServerPort = process.env.RENDERER_USE_WDS_PORT; | ||
if (webpackDevServerPort && context.extensionMode !== vscode.ExtensionMode.Release) { | ||
this.preloads.push(vscode.Uri.parse(`http://localhost:${webpackDevServerPort}/index.js`)); | ||
} else { | ||
this.preloads.push(vscode.Uri.file(path.join(context.extensionPath, 'out/client/index.js'))); | ||
} | ||
} | ||
|
||
/** | ||
* Called to render a cell. | ||
*/ | ||
public render(document: vscode.NotebookDocument, output: vscode.CellDisplayOutput, mimeType: string): string { | ||
const renderData = output.data[mimeType]; | ||
this.ensureDevTools(document); | ||
|
||
// Here we output a script tag that calls a function we exposed in the | ||
// renderer client after it loads. Its contents are are output data as JSON. | ||
// renderer client in its `online`. Its contents are are output data as JSON. | ||
// You could also preprocess your data before passing it to the client. | ||
return ` | ||
<script src="http://localhost:8111/index.js"></script> | ||
<script type="renderer/${viewType}" data-mime-type="${mimeType}" onload="${onLoad}"> | ||
${JSON.stringify(output.data[mimeType])} | ||
${JSON.stringify(renderData)} | ||
</script> | ||
`; | ||
} | ||
|
||
/** | ||
* Little utility to open the webview dev tools on first render. | ||
* Todo: unnecessary once https://github.com/microsoft/vscode/issues/96626 | ||
*/ | ||
private async ensureDevTools(document: vscode.NotebookDocument) { | ||
if (this.context.extensionMode === vscode.ExtensionMode.Development && !this.hasOpenedDevTools.has(document)) { | ||
await vscode.commands.executeCommand('workbench.action.webview.openDeveloperTools'); | ||
this.hasOpenedDevTools.add(document); | ||
} | ||
} | ||
} |
Oops, something went wrong.