@@ -6,31 +6,44 @@ import * as path from 'path';
66// this method is called when your extension is activated
77// your extension is activated the very first time the command is executed
88export function activate ( context : vscode . ExtensionContext ) {
9- let disposable = vscode . commands . registerCommand ( 'p5-complete.addComp' , async ( ) => {
9+
10+ // register the command with vscode.
11+ // so that we can run it from command pallete.
12+ // this command is also defined in package.json
13+ let disposable = vscode . commands . registerCommand ( "p5-complete.openSketch" , async ( ) => {
14+
15+ // create a new webview
16+ // this is used to show the sketch
1017 const panel = vscode . window . createWebviewPanel (
1118 "p5Sketch" ,
1219 "p5 Sketch" ,
20+ // use split mode
1321 vscode . ViewColumn . Two ,
1422 {
23+ // enable javascript
1524 enableScripts : true ,
1625 }
1726 )
1827
28+ // find all the javascript files in the workspace
1929 const files = await vscode . workspace . findFiles ( "*.js" ) ;
20- // push index.js to last
21-
30+
31+ // map the files to script tag
2232 const scripts = files . map ( file => {
2333 const path = panel . webview . asWebviewUri ( file ) . toString ( ) ;
2434 return `<script src="${ path } "></script>`
2535 } ) . join ( "" ) ;
26-
27- const p = vscode . Uri . file ( path . join ( context . extensionPath , "p5.js" ) ) ;
28- const p5Path = panel . webview . asWebviewUri ( p ) ;
29-
3036
37+ // get url of p5.js file
38+ const p5Path = panel . webview . asWebviewUri (
39+ vscode . Uri . file ( path . join ( context . extensionPath , "p5.js" ) )
40+ ) ;
41+
42+ // add everything to html content of webview
3143 panel . webview . html = `<script src="${ p5Path } "></script>${ scripts } `
3244 } ) ;
3345
46+ // I don't know
3447 context . subscriptions . push ( disposable ) ;
3548}
3649
0 commit comments