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]

  • Thanks! Here's what I got:

     ERR [Extension Host] TypeError: doc.processRefs is not a function
    workbench.desktop.main.js:90 [Extension Host] TypeError: doc.processRefs is not a function
    T @ workbench.desktop.main.js:90
    $logExtensionHostMessage @ workbench.desktop.main.js:1573
    N @ workbench.desktop.main.js:1573
    M @ workbench.desktop.main.js:1573
    H @ workbench.desktop.main.js:1573
    G @ workbench.desktop.main.js:1573
    (anonymous) @ workbench.desktop.main.js:1573
    invoke @ workbench.desktop.main.js:86
    deliver @ workbench.desktop.main.js:86
    fire @ workbench.desktop.main.js:86
    fire @ workbench.desktop.main.js:553
    ne.onmessage @ workbench.desktop.main.js:1671
    workbench.desktop.main.js:615   ERR [Extension Host] TypeError: doc.processRefs is not a function
    workbench.desktop.main.js:90 [Extension Host] TypeError: doc.processRefs is not a function
    T @ workbench.desktop.main.js:90
    $logExtensionHostMessage @ workbench.desktop.main.js:1573
    N @ workbench.desktop.main.js:1573
    M @ workbench.desktop.main.js:1573
    H @ workbench.desktop.main.js:1573
    G @ workbench.desktop.main.js:1573
    (anonymous) @ workbench.desktop.main.js:1573
    invoke @ workbench.desktop.main.js:86
    deliver @ workbench.desktop.main.js:86
    fire @ workbench.desktop.main.js:86
    fire @ workbench.desktop.main.js:553
    ne.onmessage @ workbench.desktop.main.js:1671
    workbench.desktop.main.js:615   ERR [Extension Host] TypeError: doc.processRefs is not a function
    workbench.desktop.main.js:90 [Extension Host] TypeError: doc.processRefs is not a function
    T @ workbench.desktop.main.js:90
    $logExtensionHostMessage @ workbench.desktop.main.js:1573
    N @ workbench.desktop.main.js:1573
    M @ workbench.desktop.main.js:1573
    H @ workbench.desktop.main.js:1573
    G @ workbench.desktop.main.js:1573
    (anonymous) @ workbench.desktop.main.js:1573
    invoke @ workbench.desktop.main.js:86
    deliver @ workbench.desktop.main.js:86
    fire @ workbench.desktop.main.js:86
    fire @ workbench.desktop.main.js:553
    ne.onmessage @ workbench.desktop.main.js:1671
    workbench.desktop.main.js:1670 Extension Host
    workbench.desktop.main.js:1670 TypeError: doc.processRefs is not a functionTypeError: doc.processRefs is not a functionTypeError: doc.processRefs is not a function

    EDIT: I also found that the optimizer works in 2.0.53 but fails in 2.0.54.

  • Here's what I got:

    Well, that was unexpected, and somewhat confusing!

    But I think I figured it out. Are you using barrels with resources in your project? I was able to repro the issue that way (although I already had a simple project to test that - I had to extend it a little to make the problem happen).

    Anyway, I'm testing a fix; hopefully, the problem I found is the one you're hitting!

  • v2.0.65.is out, and I hope it fixes this issue. Please let me know.

  • You were right, I had barrels with resources! That fixed it, thank you very much.

  • That fixed it, thank you very much

    You're welcome.

    Btw - one other question. A while ago, I added a post-build optimizer, which performs some optimizations that the source-to-source optimizer can't. I left it off by default, but I'm not sure if anyone other than Gavriel noticed it or tried turning it on. If you're not already using it, could you let me know a) if it breaks anything for you, and b) how much more it saves (when its enabled, the extension reports the sizes before and after the post build optimizer runs)? Just type "Post Build" into the vscode settings page to find it.

  • Yeah, I've noticed a big reduction in code size when I have it on, thanks for adding it!

    For this project, I get:
    Original (without optimizer): code: 57529 data: 16999
    Sizes for optimized-MY-APP.original-venu: code: 53351 data: 17714
    Sizes for optimized-MY-APP-venu: code: 47089 data: 17714

    I also have "Remove Argc" and "Post Build PRE" on. Basically, I'm saving 6.5k of memory by having it on!

  • it looks like the optimizer doesn't like SDK 6.2.0:

    Starting optimization step...
    ERROR: Internal: TypeError: Cannot read properties of undefined (reading '0')
    TypeError: Cannot read properties of undefined (reading '0')
    at collectClassInfo (.vscode/extensions/markw65.prettier-extension-monkeyc-2.0.65/node_modules/@markw65/monkeyc-optimizer/build/chunk-QINU6R5E.cjs:17416:51)
    at analyze (.vscode/extensions/markw65.prettier-extension-monkeyc-2.0.65/node_modules/@markw65/monkeyc-optimizer/build/chunk-QINU6R5E.cjs:17586:3)
    at async optimizeMonkeyC (.vscode/extensions/markw65.prettier-extension-monkeyc-2.0.65/node_modules/@markw65/monkeyc-optimizer/build/chunk-QINU6R5E.cjs:17747:17)
    at async Promise.all (index 47)
    at async generateOptimizedProject (.vscode/extensions/markw65.prettier-extension-monkeyc-2.0.65/node_modules/@markw65/monkeyc-optimizer/build/chunk-QINU6R5E.cjs:29695:5)
    at async buildOptimizedProject (.vscode/extensions/markw65.prettier-extension-monkeyc-2.0.65/node_modules/@markw65/monkeyc-optimizer/build/chunk-QINU6R5E.cjs:29356:59)

    * The terminal process terminated with exit code: 1.
    * Terminal will be reused by tasks, press any key to close it.

  • They've added some "junk" to api.mir that my parser didn't handle. There's an easy fix, so I'm just working on tests.

    So far, one of my tests broke because the type checker no longer supports accessing non-static const members via ClassName.FOO. But since that never really worked as expected anyway I've just rewritten the test.

    Another one broke due to what looks like a compiler error in 6.2.0 (in fact, I think it's a bug I reported against 4.1.6 that was fixed in 4.1.7).

    Once I've figured out all the issues, I'll post a new version of the compiler.

  • v2.0.66 is out, and should work with sdk-6.2.0

  • I think the conclusion is that its not safe to convert "Toybox.foo has :bar" to true based on api.mir and compiler.json because (as I suspected and Gavriel confirmed) the minimum version gets updated as new firmware is rolled out; but there's no guarantee that any given device actually got the update.

    It came up in another thread that Garmin is actually doing this with their optimizer - and as described above, that seems to be unsafe.

    But I just happened to make an interesting discovery. I just bought a FR 955, and tried to install my (currently in beta) data field on it. And the IQ store told me it couldn't do that until I updated the firmware.

    My data field runs on pretty much everything, and is built with minSdkVersion=1.2.0. I checked the 955, and it currently had 4.1.x installed, but <sdk>/Devices/fr955/compiler.json says "connectIQVersion": "4.2.2".

    So it seems that because I had built with that version of compiler.json, it wouldn't let my data field run on an fr955 which "only" had 4.1.x installed, even though it will happily run on an fr235 with 1.4.4 installed.

    In other words, as far as I can see, it *is* safe to optimize "Toybox.foo has :bar" to true, if compiler.json says it must be present - although I might ultimately have to generate one set of source code per device to do so...