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'm not using it because I have no clue what it would do for me

    It does three main things, and you can use all three independently

    1. Its a code formatter. You can use it to format your code, if you like the way it does it.
    2. It provides lots of vscode language support that the garmin plugin doesn't. Such as Goto Definition, Goto Refernces, outlining, symbol lookup, links from Toybox modules to their documentation, a certain amount of linting - it will show you syntax errors as you type, and show you symbols that are going to fail to resolve at runtime as you type, rather than waiting for the compiler, or in cases where the compiler fails to notice, at runtime.
    3. It will produce an optimized copy of your code (hidden away in the bin directory) and build and run that for you. WIth the older compilers I get a roughly 20% code size reduction from it on my projects. The latest compiler does most of what mine does, but i still get about 5-7% reduction.
  • Ok, so 2 and 3 don't matter to me.  Thanks, that's all I need to know.  If you process an mc file, why not rename old original something like *.mcold and make the output the new .mc?  That would make sense for making the code prettier, with an old version if something breaks?  Things would work fine with the Garmin extension, or in Eclipse for that matter.

  • If you process an mc file, why not rename old original something like *.mcold and make the output the new .mc? 

    Because thats not how the vscode code formatting api works. And as of a fairly recent vscode release, it now keeps a timeline of all your files anyway (even without source control), so you can revert changes going back weeks anyway.

    If you wanted to use prettier directly from the command line, you could absolutely do that, and have it save backups however you like. You don't even need the vscode extension for that (you would need to install @markw65/prettier-plugin-monkeyc as a plugin for prettier) and if there's a prettier plugin for eclipse you could probably hook it up in eclipse too. The rest of it is pretty much vscode specific.

  • So maybe you shouldn't use the VS Code formatting API!  Sound silly to me to put the new source somewhere other than source!  If I just want to build something with the new source, how would I do it in eclipse?

  • But this is exactly what garmin do in the beta compiler: it uses the "intermediate representation (IR)". The optimized code of the prettier extension is kind of similar, just 1 step before that. And because there's no other way to communicate it to the compiler it's put to a folder under bin. It's good that it does that for 2 reasons:
    1. (main) because I am the developer who is writing my code, and I don't want the "optimized' code to override my code anywhere (not in the editor, and not in git). I called it "optimized" because it is optimized for the compiler but not for human eye.
    2. it it good that it puts the files under bin (and not in /tmp for example) because it's easy to look at the files this way.

  • I think we're saying the same thing about how the lookup works and the only thing you can change is to chose 3 possible starting points:
    g: start in the local level
    self.g (start 1 level higher that local, no matter where you are and no matter if self has any logical meaning)
    $.... start at the highest level.

    However I still think that it is a bug, that Toybox.Application.Properties.WatchUi.Lang.Number works. IMHO it shouldn't and I would be surprised if in Garmin they know this (even more if this was intended to work like this) and wouldn't be surprised if they'll "fix" it in the future.

  • No, it rewrites your mc in a different format in a weird place and makes changes to the base code..  No IR involved!

    Again, why does it seem you are the only one using this?

  • There are 2 types of features related to Garmin:

    1. features that everyone use except you => nobody should use them, and actually they shouldn't exist
    2. features that you use => everyone should use

    Why does it bother you if I am the only one using a feature (which I'm pretty sure is true for some, I am the early adopter, but probably will change in the future). BTW I'm pretty sure Mark wouldn't implement something just for me, I guess there are at least 2 users :) 

  • Why does it seem you are the only one using this?  12 pages of posts and just you and Mark..

  • You, see, exactly what I wrote above :) BTW according to your calculation you're the only one using the whole ConnectIQ Discussion forum... Do you know that you can unsubscribe from a thread you're not interested in (instead of trying to silence people who are using some feature you don't)