Code generator plugin, how to open new sketch window and populate with generated code? #16
Replies: 6 comments 1 reply
-
You can use fs from Node.js or one of your tools (and spawn a process) to generate files and folders.
What do you want to do with the generated files? Where should the extension generate them? I created a short example of how to generate a sketch from user input into the user's sketchbook: PaulStoffregen/secure_plugin_vscode@43e46aa. In action: openFolder.mov
It's not trivial; I also had to look into Theia's code to see how to achieve it.
You can use built-in VS Code commands to open a new window: https://code.visualstudio.com/api/references/commands. My example includes a few more links. I adjusted (PaulStoffregen/secure_plugin_vscode@9187b77) the I hope this helps, thanks for using the API, and if you have any questions, feel free to ask. |
Beta Was this translation helpful? Give feedback.
-
Arduino IDE supports a single sketch per workspace; once the "current" sketch is loaded in IDE2, it won't unload or change. Hence, this value changes only once per sketch window from If the API and your extension run in another environment that supports multiple sketches per workspace, for example, VS Code, this value could change more than once per workspace. |
Beta Was this translation helpful? Give feedback.
-
Wow, thanks! Tried |
Beta Was this translation helpful? Give feedback.
-
An exciting moment on my 4th day of learning Typescript, got it to actually fill in the generated code! |
Beta Was this translation helpful? Give feedback.
-
Quick novice question... I brought in your changes to package.json and package-lock.json. Everything seems fine when I build with "npm run compile". But if I try running "vsce package", I'm getting this error:
Any chance you could point me to where I can get the stuff it wants to find in node_modules/vscode-arduino-api ? |
Beta Was this translation helpful? Give feedback.
-
I'm trying to recreate a Java plugin I wrote for the old Arduino IDE, which helps the user to create an encryption key, and can automatically generates a few sketches with their key embedded in the sketch code. Learning typescript as I go, but happy to say my effort so far has the first key generation part working in Arduino IDE 2.3.3 thanks to this API and quite a lot of studying Earle F. Philhower's arduino-littlefs-upload plugin.
But now I'm stuck on the part of creating a new sketch and populating it with generated code. Hoping you can give me a hint on how to accomplish this?
Something I tried which didn't work was trying to create a Virtual Document using vscode.TextDocumentContentProvider. I did manage to get generated code to appear as a new tab in the current sketch...
Sadly, Arduino IDE seems to completely ignore this tab.
In the old Java IDE, my plugin just created a temporary folder, wrote the code into files, and then called Base.INSTANCE.handleOpen(newFile). Really hoping there's a way to do something similar with the new IDE. Maybe it's "obvious" and I've just been missing something?
Beta Was this translation helpful? Give feedback.
All reactions