From c222520beb8dc339108bac32aec3816177ff4884 Mon Sep 17 00:00:00 2001 From: Manmeet Maan Date: Sun, 5 Jul 2020 17:47:58 +0530 Subject: [PATCH] add comments --- extension/CHANGELOG.md | 9 --------- extension/package.json | 4 ++-- extension/src/extension.ts | 27 ++++++++++++++++++++------- 3 files changed, 22 insertions(+), 18 deletions(-) delete mode 100644 extension/CHANGELOG.md diff --git a/extension/CHANGELOG.md b/extension/CHANGELOG.md deleted file mode 100644 index f82c36c..0000000 --- a/extension/CHANGELOG.md +++ /dev/null @@ -1,9 +0,0 @@ -# Change Log - -All notable changes to the "p5-complete" extension will be documented in this file. - -Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file. - -## [Unreleased] - -- Initial release \ No newline at end of file diff --git a/extension/package.json b/extension/package.json index c6c7c70..1319cc0 100644 --- a/extension/package.json +++ b/extension/package.json @@ -10,13 +10,13 @@ "Other" ], "activationEvents": [ - "onCommand:p5-complete.addComp" + "onCommand:p5-complete.openSketch" ], "main": "./out/extension.js", "contributes": { "commands": [ { - "command": "p5-complete.addComp", + "command": "p5-complete.openSketch", "title": "Open this sketch" } ] diff --git a/extension/src/extension.ts b/extension/src/extension.ts index 9842b43..b5fa669 100644 --- a/extension/src/extension.ts +++ b/extension/src/extension.ts @@ -6,31 +6,44 @@ import * as path from 'path'; // this method is called when your extension is activated // your extension is activated the very first time the command is executed export function activate(context: vscode.ExtensionContext) { - let disposable = vscode.commands.registerCommand('p5-complete.addComp', async () => { + + // register the command with vscode. + // so that we can run it from command pallete. + // this command is also defined in package.json + let disposable = vscode.commands.registerCommand("p5-complete.openSketch", async () => { + + // create a new webview + // this is used to show the sketch const panel = vscode.window.createWebviewPanel( "p5Sketch", "p5 Sketch", + // use split mode vscode.ViewColumn.Two, { + // enable javascript enableScripts: true, } ) + // find all the javascript files in the workspace const files = await vscode.workspace.findFiles("*.js"); - // push index.js to last - + + // map the files to script tag const scripts = files.map(file => { const path = panel.webview.asWebviewUri(file).toString(); return `` }).join(""); - - const p = vscode.Uri.file(path.join(context.extensionPath,"p5.js")); - const p5Path = panel.webview.asWebviewUri(p); - + // get url of p5.js file + const p5Path = panel.webview.asWebviewUri( + vscode.Uri.file(path.join(context.extensionPath, "p5.js")) + ); + + // add everything to html content of webview panel.webview.html = `${scripts}` }); + // I don't know context.subscriptions.push(disposable); }