From a2a6ff8ad08abefd1669810e77115dd8e9d58d58 Mon Sep 17 00:00:00 2001 From: Vyacheslav Matyukhin Date: Mon, 20 Jun 2022 18:06:30 +0300 Subject: [PATCH] vscode: configuration for show* --- packages/vscode-ext/media/previewWebview.js | 18 ++++++++--------- packages/vscode-ext/package.json | 22 ++++++++++++++++++++- packages/vscode-ext/src/preview.ts | 2 ++ 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/packages/vscode-ext/media/previewWebview.js b/packages/vscode-ext/media/previewWebview.js index 6d91b1b9..556a893b 100644 --- a/packages/vscode-ext/media/previewWebview.js +++ b/packages/vscode-ext/media/previewWebview.js @@ -1,19 +1,17 @@ -// based on https://github.com/microsoft/vscode-extension-samples/blob/main/custom-editor-sample/media/catScratch.js (function () { - console.log("hello world"); const vscode = acquireVsCodeApi(); const container = document.getElementById("root"); const root = ReactDOM.createRoot(container); - function updateContent(text) { + function updateContent(text, showSettings) { root.render( React.createElement(squiggle_components.SquigglePlayground, { code: text, - onCodeChange: (code) => { - vscode.postMessage({ type: "edit", text: code }); - }, showEditor: false, + showTypes: Boolean(showSettings.showTypes), + showControls: Boolean(showSettings.showControls), + showSummary: Boolean(showSettings.showSummary), }) ); } @@ -23,14 +21,14 @@ const message = event.data; // The json data that the extension sent switch (message.type) { case "update": - const text = message.text; + const { text, showSettings } = message; // Update our webview's content - updateContent(text); + updateContent(text, showSettings); // Then persist state information. // This state is returned in the call to `vscode.getState` below when a webview is reloaded. - vscode.setState({ text }); + vscode.setState({ text, showSettings }); return; } @@ -38,6 +36,6 @@ const state = vscode.getState(); if (state) { - updateContent(state.text); + updateContent(state.text, state.showSettings); } })(); diff --git a/packages/vscode-ext/package.json b/packages/vscode-ext/package.json index 47ac5c1f..9dc91e4f 100644 --- a/packages/vscode-ext/package.json +++ b/packages/vscode-ext/package.json @@ -77,7 +77,27 @@ "mac": "cmd+k v", "when": "editorLangId == squiggle" } - ] + ], + "configuration": { + "title": "Squiggle", + "properties": { + "squiggle.playground.showTypes": { + "type": "boolean", + "default": false, + "description": "Whether to show the types of outputs in the playground" + }, + "squiggle.playground.showControls": { + "type": "boolean", + "default": false, + "description": "Whether to show the log scale controls in the playground" + }, + "squiggle.playground.showSummary": { + "type": "boolean", + "default": false, + "description": "Whether to show the summary table in the playground" + } + } + } }, "scripts": { "vscode:prepublish": "yarn run compile", diff --git a/packages/vscode-ext/src/preview.ts b/packages/vscode-ext/src/preview.ts index c6d3e212..04c57c86 100644 --- a/packages/vscode-ext/src/preview.ts +++ b/packages/vscode-ext/src/preview.ts @@ -30,6 +30,8 @@ export const registerPreviewCommand = (context: vscode.ExtensionContext) => { panel.webview.postMessage({ type: "update", text: editor.document.getText(), + showSettings: + vscode.workspace.getConfiguration("squiggle").playground, }); };