diff --git a/extension.js b/extension.js index dd49863..ad435a8 100644 --- a/extension.js +++ b/extension.js @@ -1,6 +1,6 @@ const vscode = require('vscode'); const { createPanel } = require('./src/panel'); -const { grabFile } = require('./src/parser'); +const { Parser } = require('./src/parser'); // This method is called when your extension is activated // Your extension is activated the very first time the command is executed @@ -17,8 +17,11 @@ function activate(context) { createPanel(context); }); - vscode.commands.registerCommand('myExtension.pickFile', () => { - grabFile(); + vscode.commands.registerCommand('myExtension.pickFile', async () => { + const fileArray = await vscode.window.showOpenDialog({ canSelectFolders: false, canSelectFiles: true, canSelectMany: false }); + const tree = new Parser(fileArray[0].path); + tree.parse(); + console.log('tree instance', tree); }); context.subscriptions.push(disposable, result); diff --git a/src/getNonce.js b/src/getNonce.js new file mode 100644 index 0000000..bd01ad0 --- /dev/null +++ b/src/getNonce.js @@ -0,0 +1,11 @@ +function getNonce() { + let text = ""; + const possible = + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + for (let i = 0; i < 32; i++) { + text += possible.charAt(Math.floor(Math.random() * possible.length)); + } + return text; + } + +module.exports = { getNonce } \ No newline at end of file diff --git a/src/panel.js b/src/panel.js index c17f994..e0cbd04 100644 --- a/src/panel.js +++ b/src/panel.js @@ -1,6 +1,12 @@ const vscode = require('vscode'); +const { getNonce } = require('./getNonce.js'); +const { Parser } = require('./parser.js'); + +// let panel; function createPanel(context) { + // if the current panel exists, then reveal the column, else make one? + // utilize method on vscode.window object to create webview const panel = vscode.window.createWebviewPanel( 'reactLabyrinth', @@ -22,8 +28,34 @@ function createPanel(context) { // render html of webview here panel.webview.html = createWebviewHTML(bundleURI); + + // will need to use onDidDispose to clear cached data and reset tree when the webview and/or application is closed + + // from my understadning, we will have to use onDidReceiveMessage to send message from the webview to and from the extension. its sent and read based on the switch case 'string' and then activates their functionality there + + // we will need to grab the value of the root file path => then make new instance of parser => call parse method on new instance => then create a func to then post a message to our flow.jsx + + // panel.webview.onDidReceiveMessage( + // async (msg) => { + // console.log('Message: ', msg) + // switch (msg.type) { + // case 'test': + // console.log('testing onDidReceiveMessage'); + + // break; + // } + // }, + // null, + // vscode.Disposable + // ); + + } +// getNonce generates a new random string each time ext is used to prevent external injection of foreign code into the html +const nonce = getNonce(); + +// function to update state in webview // function to create the HTML page for webview function createWebviewHTML(URI) { @@ -38,11 +70,18 @@ function createWebviewHTML(URI) {
- + +