Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions extension/CHANGELOG.md

This file was deleted.

4 changes: 2 additions & 2 deletions extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
Expand Down
27 changes: 20 additions & 7 deletions extension/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<script src="${path}"></script>`
}).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 = `<script src="${p5Path}"></script>${scripts}`
});

// I don't know
context.subscriptions.push(disposable);
}

Expand Down