But I'm stuck on how to use Typescript to cause Arduino IDE 2.3 to open it as a new sketch. In Java on the old IDE, it was just a matter of writing the files to a temporary folder and then calling Base.INSTANCE.handleOpen(newFile).
Maybe the new API has a way I'm just missing? So far I can't find it. I spent way too much time going down a rabbit hole of vscode extension tutorials which seemed to say Virtual Document using vscode.TextDocumentContentProvider was the way forward, but sadly that just creates a new tab in the existing sketch which is completely ignored by Arduino IDE 2. Here's how it looks (but doesn't work).
Not sure where to ask for help? Tried starting a discussion on the vscode-arduino-api repository, but so far seems deserted. Maybe @ptillisch might know where I should ask? I had previously asked on Arduino IDE issue #58, and was given some really good advice that's help me get this far, but sadly issue #58 been locked for almost a year.
@ptillisch - Does Arduino have a preferred way for boards packages to install VS code plugins?
Yesterday I wrote a utility which copies the .vsix file to {homedir}/.arduinoIDE/plugins and added a line in the post_install script to run it.
I also put some code into the utility to check ARDUINO_USER_AGENT missing "arduino-cli" or if the folder {homedir}/.arduinoIDE doesn't exist, which would (probably) imply an install by Arduino CLI not meant to be used with Arduino IDE.
My code checks if the .vsix file was already present and matches, so it doesn't have to write. If it does write the file, it then prints a message advising the user they will need to restart the Arduino IDE before the plugin can be used. Maybe Ctrl-Shift-P and "Reload Window" would be sufficient?
It all feels kinda kludgy, but still better than asking people to manually copy a file to a specific place right after they've used Boards Manager to install a package.
Searching the Arduino CLI documentation hasn't turned up any advice. Maybe this question just hasn't come up much yet? Seems like maybe only a few VS code extensions specifically meant for Arduino IDE may exist so far.
I think the platform should not do anything, such as downloading VSIX and copying files, but tell the client what to do if they want to do anything at all.
Here is an idea:
the Arduino CLI and the platform definitions are already IDE-specific in some way; for example, the custom debug options defined in the platform: Platform specification - Arduino CLI
platform developers can define a series of actions in the platform.txt that will be part of the PlatformInstallResponse.Result grpc object after installing a platform via the CLI. Clients, in this case, the Arduino IDE, can execute these actions.
the actions are defined as VS Code/Theia/Arduino IDE compatible commands: a string as the command identifier and optional arguments as an array of JSON serializable objects. (See VS Code commands and built-in command)
Arduino should consider incliding built-in VSIX features from Theia, so extensions could be installed with the available commands.
3rd-party Arduino plugins (VS Code extensions) can be deployed to open VSX, so Theia can natively deal with them. Here is an example.
For example, to install an extension and reload the window, the platform developer could write something like this (in a pseudo language):
But I will just quickly mention a couple unresolved minor issues that came up in testing. Could be I made novice mistakes, as my total time learning Typescript is still only about 1 week. Still, could be stumbling blocks other people might encounter?
Using Ctrl-Shift-P Window Reload doesn't seem to load the freshly installed extension if it's a .vsix. But it does work nicely when I try with the original folder after running npm run compile. I have no idea why.
After installing the Teensy package and restarting the IDE, if a non-Teensy board is still selected, I can run the extension's commands but the findTool() function I copied from arduino-littlefs-upload returns undefined even though teensy-tools is now installed. After selecting Teensy from the drop-down list of detected boards, then it works fine. It continues working even after selecting other non-Teensy boards.
I still have so much to learn about Typescript and VS code extensions. In my dream world of infinite programming hours every day, I would really want to create a GUI that appears in the left side bar, like Boards Manager and Library Manager. Early attempts has a viewContainer defined in package.json that made the icon appear and a blank sidebar when I clicked it, but with only a couple days and my inexperience with Typescript, I couldn't figure out how to create a working Webview and make it appear in the side bar. Maybe someday...
This won't work. This was generally a false assumption from here. The Arduino IDE discovers the VSIX when the app starts, not when the browser windows open, reload won't help either. The app must be restarted, or Theia APIs/commands must be used to install a VSIX.
After installing the Teensy package and restarting the IDE, if a non-Teensy board is still selected, I can run the extension's commands but the findTool() function I copied from arduino-littlefs-upload returns undefined even though teensy-tools is now installed. After selecting Teensy from the drop-down list of detected boards, then it works fine. It continues working even after selecting other non-Teensy boards.
I will debug this and update this thread if there is a problem with Arduino IDE/Theia.
If it's a problem in the VS Code Arduino APIs or in the Teensy security extension, I will submit a PR.
If pioneers like you do not request such features, there won't be a standard way of supporting Arduino IDE extensions/plugins from the platform in the near future. I am happy to support you with the IDE development part.
Wow, yes, that's pretty much what I wanted GUI-wise. I know it's just static info with links... but if could it could be dynamic, the ideal GUI would disable the 3 sketch buttons until the key is created. And perhaps it would disable itself when a non-Teensy board get selected.
I did run into a possible issue with the IDE. At first it didn't work at all on Linux. But then I tried on MacOS and it worked great. I captured the console messages (easy with Linux) and saw this:
2024-10-13T07:52:47.849Z root INFO [teensysecurity-0.0.1.vsix]: trying to decompress into "/tmp/vscode-unpacked/teensysecurity-0.0.1.vsix"...
2024-10-13T07:52:47.855Z root INFO [teensysecurity-0.0.1.vsix]: already found
2024-10-13T07:52:47.858Z root INFO [teensysecurity-0.0.1.vsix]: already copied.
Sure enough, when I looked in /tmp/vscode-unpacked/ it has the prior copy of the .vsix content (vsix appears to just be a renamed .zip file).
So even though I put a new version of teensysecurity-0.0.1.vsix into my .arduinoIDE/plugins folder, Arduino IDE keeps using the previous copy even after I restart the IDE.
Yes, I will create a feature request on github, if nobody else does it first. But I would prefer to wait a short time while we beta test.
Already we have some beta testing feedback on the PJRC forum. People hit the same issue where the commands wouldn't work (probably findTool but not enough info to know for sure) until they selected a board.
If there are more install issue like the Linux /tmp/vscode-unpacked/ leftover files, I believe discovering these first and incorporating them into the feature request will ultimately save everyone's time. So I'm hoping to wait until at least a few more beta test cycles before creating a written feature request for the Arduino CLI developers.
This is the C code I'm using (so far) to install the .vsix file.
A perl script turns the .vsix into a .c and .h file with the raw data in an array of bytes. Then this code creates the plugins folder, if needed. If other versions exist, it deletes them. It then writes the .vsix file.
It also tries to detect if the install is Arduino CLI without Arduino IDE, using the ARDUINO_USER_AGENT environment variable and also by checking whether the ~/.arduinoIDE directory exists.
If anyone is watching this conversation and wants a way to install their plugin (before a glorious but probably distant future where Arduino CLI supports it) hopefully this can help.
It's an Arduino IDE bug. I will look into it, but I need to set up the dev env on my Windows notebook, and it will probably take some time to get the fixes into the nightly/release builds.