Big update to prettier-extension-monkeyc

I've posted about prettier-extension-monkeyc before, but I've added a bunch of new features that developers will probably like (well, I've been missing them, so maybe you have too).

The new features it implements for VSCode include:

  • Goto Definition. Point at a symbol, Ctrl/Cmd click, and it will take you to the definition. Or F12
  • Goto References. Right click on a symbol and select "Goto References". It will show you all the references. Or Shift-F12
  • Peek Definition/Peek References. Same as above, but in a popup window so you don't lose your place in the original document.
  • Rename Symbol. Right click on a local, function, class or module name, and select "Rename Symbol". It will rename all the references. It doesn't yet work for class members/methods.
  • Goto Symbol. Type Ctrl/Cmd-Shift-O and pick a symbol from the drop down (which has a hierarchical view of all symbols in the current file). This also appears as an outline across the top of the file.
  • Open Symbol By Name. Type Ctrl/Cmd-T, then start typing letters from a symbol name. A drop down will be populated with all matching symbols from anywhere in your project.

Older features include a prettier based formatter for monkeyc, and a monkeyc optimizer that will build/run/export an optimized version of your project.

[edit: My last couple of replies seem to have just disappeared, and the whole conversation seems to be in a jumbled order, so tldr: there's a new test-release at https://github.com/markw65/prettier-extension-monkeyc/releases/tag/v2.0.9 which seems to work for me on linux. I'll do more verification tomorrow, and push a proper update to the vscode store once I'm sure everything is working]

  • It seems that they've switched to using LZMA2 compression - and I can't find a zip library that supports it. There are libraries that support LZMA2 compression/decompression, so maybe it's not too hard to add to an existing zip implementation.

  • Yeah, I also looked into the iq file yesterday, and that reminded me the changelog of 8.4.0 that they changed to 7zip

  • I've found a suitable library, which seems to be the source code for 7zip itself compiled into WASM. In any case, it works for both new and old .iq files.

    I'm trying to test everything now, but Garmin seem to have deliberately made things hard. After downloading the new Device files (which I did while updating to 8.4.0), lots of devices refuse to build with any of the 8.2.x sdks. This seems like really bad backward compatibility, even for Garmin...

    Anyway, 8.1 still seems to work, so I can still test both the old and new iq formats. [edit: I was wrong - I can still build .iq files which contain fr955 targets using 8.1, but I can't build for the simulator if I target fr955. Fortunately, I have Time Machine backups, so was able to restore to older device files, and I can build again]

  • I also don't like that they are forcing us to build only with the latest SDK. There might be some good reasons for it that we don't know, but maybe it doesn't matter. I mean if devs are forced to do the upgrade then you could just do the same, after all the number of devs who still build old apps with old SDK for old devices only must be diminishing by now.

    Update: maybe except for good reasons, i.e: until Garmin fixes 8.4.0 related bugs (no ERA) most devs will probably stick to 8.3.0

  • After following this work from time to time I have done a trial now for one of my projects.

    All works fine when I build for any specific device, but following error occurs if I export the project. Is there any way to overcome the call stack size limit?

    * Ejecutando tarea: omonkeyc: export

    Starting optimization step...
    ERROR: Internal: RangeError: Maximum call stack size exceeded
    RangeError: Maximum call stack size exceeded
    at String.match (<anonymous>)
    at Object.parse (/Users/Inigo/.vscode/extensions/markw65.prettier-extension-monkeyc-2.0.119/node_modules/@markw65/prettier-plugin-monkeyc/build/prettier-plugin-monkeyc.cjs:15:54764)
    at Object.parse (/Users/Inigo/.vscode/extensions/markw65.prettier-extension-monkeyc-2.0.119/node_modules/prettier/index.js:7515:23)
    at coreFormat (/Users/Inigo/.vscode/extensions/markw65.prettier-extension-monkeyc-2.0.119/node_modules/prettier/index.js:8829:18)
    at formatWithCursor2 (/Users/Inigo/.vscode/extensions/markw65.prettier-extension-monkeyc-2.0.119/node_modules/prettier/index.js:9021:18)
    at /Users/Inigo/.vscode/extensions/markw65.prettier-extension-monkeyc-2.0.119/node_modules/prettier/index.js:38183:12
    at Object.format (/Users/Inigo/.vscode/extensions/markw65.prettier-extension-monkeyc-2.0.119/node_modules/prettier/index.js:38197:12)
    at formatAst (/Users/Inigo/.vscode/extensions/markw65.prettier-extension-monkeyc-2.0.119/node_modules/@markw65/monkeyc-optimizer/build/chunk-BOVSYC7N.cjs:20065:14)
    at /Users/Inigo/.vscode/extensions/markw65.prettier-extension-monkeyc-2.0.119/node_modules/@markw65/monkeyc-optimizer/build/chunk-BOVSYC7N.cjs:30342:17
    at async Promise.all (index 9)

  • v2.0.120 is out.

    Fixes the post build optimizer for .iq files with sdk-8.4

    Completes the fix for the issue reported here (sorry for the delay).

  • My solution was to put the ConnectIQ/Devices directory into git. For now I've only put a few versions in, but I may write a script to put the state of the Devices directory at each sdk release into source control, then when I switch to a particular sdk, I could switch to the corresponding tag in git, and guarantee that builds work the same way they did at the time the sdk was released...

    I mean if devs are forced to do the upgrade then you could just do the same

    True, but when I find what appears to be a bug in 8.4, it's nice to be able to go back and see if it's new, or a long term problem. Garmin is much more willing to fix newly introduced bugs, than long standing ones...

    Also, there are some very long standing bugs. For some people, me included, it's impossible to connect to ANT devices in the simulator in any SDK after 4.0.10. So I still switch back to that for some of my testing.

  • Fixed in 2.0.120.

    For now, the optimized .iq files are still written using zip/deflate, so they may well be larger than the input .iq files. I'll probably switch to 7z for writing too in the next release, but wanted to get something that works out (I verified that I could upload an app to the connect-iq store).

    I also noticed that for now, they're still using zip format for compiled barrels, so I didn't change the code for handling those. I expect they'll switch that over too at some point, so I'll try to switch that code over to 7zip too (which will work with both formats).

  • but following error occurs if I export the project. Is there any way to overcome the call stack size limit?

    The stack limit is generally large enough that if this happens, it's an infinite recursion bug, and increasing the stack size won't help.

    Looking at this it appears to be failing while trying to format something - which is surprising! Would you be willing to share the code that causes this so I can try to debug it?