Update to target VS Code 1.25+

This commit is contained in:
Matt Bierner
2018-07-18 18:56:40 -07:00
parent e7bd806c87
commit f63e84e288
5 changed files with 367 additions and 366 deletions

View File

@ -10,12 +10,12 @@ Demonstrates VS Code's [webview API](https://code.visualstudio.com/docs/extensio
- Sending messages from a webview to an extension.
- Using a basic content security policy.
- Webview lifecycle and handling dispose.
- Saving and restoring state when the panel goes into the background. (Requires VS Code 1.25+)
- Serialization and persistence across VS Code reboots. (Requires VS Code 1.25+)
- Saving and restoring state when the panel goes into the background.
- Serialization and persistence across VS Code reboots.
## Running the example
- Open this example in VS Code 1.23+
- Open this example in VS Code 1.25+
- `npm install`
- `npm run watch` or `npm run compile`
- `F5` to start debugging

View File

@ -3,7 +3,7 @@
(function () {
const vscode = acquireVsCodeApi();
const oldState = vscode.getState && vscode.getState();
const oldState = vscode.getState();
const counter = document.getElementById('lines-of-code-counter');
console.log(oldState);
@ -14,7 +14,7 @@
counter.textContent = currentCount++;
// Update state
vscode.setState && vscode.setState({ count: currentCount });
vscode.setState({ count: currentCount });
// Alert the extension when the cat introduces a bug
if (Math.random() < Math.min(0.001 * currentCount, 0.05)) {

File diff suppressed because it is too large Load Diff

View File

@ -4,7 +4,7 @@
"version": "0.0.1",
"publisher": "ms-vscode",
"engines": {
"vscode": "^1.23.0"
"vscode": "^1.25.0"
},
"categories": [
"Other"

View File

@ -19,10 +19,9 @@ export function activate(context: vscode.ExtensionContext) {
}
}));
// Serializers only introduced in VS Code 1.25+
if ((vscode.window as any).registerWebviewPanelSerializer) {
if (vscode.window.registerWebviewPanelSerializer) {
// Make sure we register a serilizer in activation event
(vscode.window as any).registerWebviewPanelSerializer(CatCodingPanel.viewType, {
vscode.window.registerWebviewPanelSerializer(CatCodingPanel.viewType, {
async deserializeWebviewPanel(webviewPanel: vscode.WebviewPanel, state: any) {
console.log(`Got state: ${state}`);
CatCodingPanel.revive(webviewPanel, context.extensionPath);
@ -125,6 +124,8 @@ class CatCodingPanel {
}
private _update() {
const z = 1 + 2;
// Vary the webview's content based on where it is located in the editor.
switch (this._panel.viewColumn) {
case vscode.ViewColumn.Two: