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]

  • I am seeing more and more more and more Stack Overflow Errors while running my app in the simulator. Until now I could run it as a regular build (no prettier optimizer) that made it easy to debug. But now I get Stack Overflow Error at some point. I think the main reason for this is the way I write the code: since this is a datafield that supports all but epix (gen1) it is highly optimized for memory size. This means that I use the following pattern:

    1. for each feature I have an annotation: feature1 or no_feature1. This is in monkey.jungle (generated based on device capabilities)

    2. for parts of the code that is not relevant for some (usually older) devices I do something like:

    function foo() {
        executeFeature1(x, y, z, ...);
    }

    (:no_feature1, :inline) private function executeFeature1(x, y, z, ...) {}
    (:feature1) private var onlyUsedInFeature1;
    (:feature1, :inline) private function executeFeature1(x, y, z, ...) {
      ...
    }

    This has the advantage that when I compile with prettier optimizer then only the code and variables that are used on the device are there. And for functions that are only called from 1 place I use the :inline annotation, because this code basically should've been in-place, and the only reason I split it is to be able to remove it AND variables, constants that are only used by newer devices that have the feature from old devices. This means that I usually pass many parameters (some of them are local variables from foo(), and some of them are local variables from foo that are a local copy of a class variable (I know prettier does this optimization, but I learn from it, so I do it almost instinctively when I use a class variable more than once in a function: var x = mX; and then use x instead of mX).

    I think that all these things together (big functions, many local variables in the functions, many functions call other functions, many parameters passed) use up the stack. It still works when building with the optimizer (because then when everything is inlined then all these passed parameters are not doubled on the stack, and also it re-uses local variables after they're not needed any more) but now I can't run the app without the optimizer, which in turn makes it hard to debug (because the code that runs is not the code that I edit, the breakpoints (I add in the file in source/Foo.mc) are not stopping the flow. Adding breakpoints in the generated source code is not very useful as I switch between devices, and because of the way my monkey file looks each device is different so it's always a different file for every device.

    I wonder if anyone using Prettier has some tips how to be able to continue to debug.