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 think it means that Garmin runs 7zip with a higher compression level. If you unzip it (with 7zip) and compare with the original, you should find that the individual .prg files are actually smaller.

  • Is there a way to disable https://github.com/markw65/monkeyc-optimizer/wiki/Extra-Reference-Type-Checks-(prettierMonkeyC.extraReferenceTypeChecks with an annotation, so it could be disabled on a per method base instead of globally?

  • I have a function that includes code like:

    function f() as Void {
      if ($ has :TTF_FONTS && font instanceof Lang.Symbol) {
        font = Graphics.getVectorFont(TTF_FONTS[font] as VectorFontOptions);
      }
    }

    I get the following error (though I guess it's technically a warning because it doesn't fail the build):

    fr955: Foo.mc:37:35: Undefined symbol TTF_FONTS

    So I changed it to:

    function f() as Void {
      if ($ has :TTF_FONTS && font instanceof Lang.Symbol) {
        font = Graphics.getVectorFont($.TTF_FONTS[font] as VectorFontOptions);
      }
    }

    Which changed the error to:

    fr955: Foo.mc:390:13: Undefined symbol $.TTF_FONTS

    The problem is that the file has only 153 lines...

    This is the global definition of TTF_FONTS:

    (:datafield, :datafield_hash, :datafield_ttf) const TTF_FONTS = { /* :size: size * ppi / 60 */
    	:simExtNumber1 => {:face => "RobotoRegular", :size => 29.570373333333336 /* 5.4424 * 326 / 60 */},
    } as Dictionary<Symbol, VectorFontOptions>;

  • Not currently. Are you suggesting something like (:no_extra_reference_checks) to mark the method?

  • Right now, if TTF_FONTS isn't declared anywhere, then no amount of $ has checks will silence the analyzer (although it probably should).

    On the other hand, if it's defined somewhere in the project, the analysis phase shouldn't complain. I guess when optimizing for a variant where it's excluded, you will see the error.

    I'll see what's needed to make the "has" guard work.

    I can't get the line 390 thing to happen - you'll need to provide a project.

  • Yes, something like that.

  • Yes, in this device TTF_FONTS is not defined.

    I'll try to reduce the size to some POC to demonstrate the line 390 bug... It'll take some time, but so far I see interesting things. I'm mass-removing code. Sometimes I see that the line number is decreased. Sometimes too much, then I add back some of the code. And now I saw that even when I remove 10-20 lines of commented out code (of a different file) it can cause the line number to be less.

    update: sent you in email

  • Is this a bug in the optimizer?

    import Toybox.Lang;
    
    function foo() as String {
        var bar = bar();
        return bar[:value] + bar[:unit];
    }
    
    function bar() as {:value as String, :unit as String} {
        var value = "--";
        var unit = "";
        return {
            :value => value,
            :unit => unit,
        };
    }
    

    ERROR> enduro3: source/POC.mc:5:12: Unexpected types for operator '+': [Null vs Null]

    project.typecheck = 3
    SDK: 8.4.1
  • No. Object types in MonkeyC are explicitly defined to allow any of the members to be missing (and also to allow arbitrary unspecified entries). 

    Garmin’s compiler doesn’t give a diagnostic here because (since about SDK-4.1.6) it doesn’t care about nullable types at all.

    I suppose it would be possible to create a stronger type, and infer it in situations like this - but then we would be determining the return type of a function by looking at its code, rather than its declaration.