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: 6 additions & 3 deletions extension.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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);
Expand Down
11 changes: 11 additions & 0 deletions src/getNonce.js
Original file line number Diff line number Diff line change
@@ -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 }
43 changes: 41 additions & 2 deletions src/panel.js
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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) {
Expand All @@ -38,11 +70,18 @@ function createWebviewHTML(URI) {
</head>
<body>
<div id="root"></div>
<script src=${URI}></script>
<script>
const vscode = acquireVsCodeApi();
window.onload = () => {
console.log('VsCode: ', vscode)
vscode.postMessage({command: 'startup'})
}
</script>
<script nonce=${nonce} src=${URI}></script>
</body>
</html>
`
)
}

module.exports = {createPanel};
module.exports = { createPanel };
Loading