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]

  • Sorry, but that doesn't mean anything to me. I'm new to VSCode. What should I do inside the Extensions tab?

  • OK, I downloaded https://github.com/markw65/prettier-extension-monkeyc/releases/download/v2.0.9/prettier-extension-monkeyc-2.0.9.vsix (BTW it's not a good name, you should've bumped the version...) and installed it, but seemingly nothing has changed. Even the Error about the Mac path is the same :(

  • I just uploaded v2.0.10, which should fix all the linux issues.

  • Perfect! Now it works.
    What I'm not sure of though is what happens after I did "Generate Optimized Project"? I see it generated the files in bin/optimized, but when I click Run I see this in the terminal:

    > Executing task: java -Xms1g -Dfile.encoding=UTF-8 -Dapple.awt.UIElement=true -jar /home/flocsy/.Garmin/ConnectIQ/Sdks/connectiq-sdk-lin-4.1.3-2022-05-10-b3aaee541/bin/monkeybrains.jar -o bin/X.prg -f /home/flocsy/garmin/X/monkey.jungle;/home/flocsy/garmin/X/barrels.jungle -y /home/flocsy/garmin/developer_key.der -d fenix6_sim -w <

    So I think it still compiles my original files. Is there anything else I need to do in order to use the optimized code?

  • Right - "Generate Optimized Project" is only really there so you can see what gets generated. I suppose you could also compile the results from the command line.

    You can also do "Build Optimized Project" - but again, you'd have to run it from the command line.

    So the most useful commands are "Build and Run Optimized Project", and "Export Optimized Project" - which do what you would expect...

    One other thing you can do is create custom configs in launch.json, with specific build options. eg release and debug builds. Something like:

        {
          "type": "omonkeyc",
          "request": "launch",
          "name": "Build and run Optimized - Release",
          "stopAtLaunch": false,
          "device": "${command:GetTargetDevice}",
          "releaseBuild": true
        },
        {
          "type": "omonkeyc",
          "request": "launch",
          "name": "Build and run Optimized - Debug",
          "stopAtLaunch": false,
          "device": "${command:GetTargetDevice}",
          "releaseBuild": false
        },
    Or you could target a launch config to a specific device if you don't like constantly picking one from a list.

  • I have annoying warnings about old devices and new languages when exporting OPTIMIZED (no warnings in the regular export):

    WARNING: release.jungle:35: d2bravo does not support language 'heb'
    WARNING: release.jungle:630: vivoactive_hr does not support language 'heb'
    WARNING: release.jungle:224: fenix3_hr does not support language 'heb'
    WARNING: release.jungle:168: edge830 does not support language 'heb'
    WARNING: release.jungle:581: vivoactive does not support language 'heb'
    WARNING: release.jungle:112: edge1030 does not support language 'heb'
    WARNING: release.jungle:147: edge520plus does not support language 'heb'
    WARNING: release.jungle:217: fenix3 does not support language 'heb'
    WARNING: release.jungle:329: fenixchronos does not support language 'heb'
    WARNING: release.jungle:203: epix does not support language 'heb'
    WARNING: release.jungle:154: edge530 does not support language 'heb'
    WARNING: release.jungle:343: fr235 does not support language 'heb'
    WARNING: release.jungle:175: edge_1000 does not support language 'heb'
    WARNING: release.jungle:336: fr230 does not support language 'heb'
    WARNING: release.jungle:371: fr630 does not support language 'heb'
    WARNING: release.jungle:126: edge1030plus does not support language 'heb'
    WARNING: release.jungle:189: edgeexplore does not support language 'heb'
    WARNING: release.jungle:161: edge820 does not support language 'heb'
    WARNING: release.jungle:42: d2bravo_titanium does not support language 'heb'
    WARNING: release.jungle:406: fr920xt does not support language 'heb'
    WARNING: release.jungle:119: edge1030bontrager does not support language 'heb'
    WARNING: release.jungle:182: edge_520 does not support language 'heb'

    Is there anything I could add to my monkey.jungle to remove these warnings? Or is that something you can add to the code that generates the optimized monkey.jungle?

    My jungle file looks like this:

    project.manifest = manifest.xml
    
    # Reset the base source path to include only source files in the source folder. The
    # default source path includes source files in the project folder and all subfolders.
    base.sourcePath = source
    base.resourcePath = $(base.resourcePath);resources-memory32K
    base.excludeAnnotations = base;no_api1_3;no_api2;memory16K
    
    
    ## Configure exclusion annotations for all supported devices with only 16K DF memory or that don't support api 2.4.0
    
    # API 1.2.0, memory16K
    epix.excludeAnnotations = base;api1_3;api2;memory32K
    
    # API 1.3.0, memory16K
    d2bravo_titanium.excludeAnnotations = base;no_api1_3;api2;memory32K
    d2bravo.excludeAnnotations = base;no_api1_3;api2;memory32K
    fenix3_hr.excludeAnnotations = base;no_api1_3;api2;memory32K
    fenix3.excludeAnnotations = base;no_api1_3;api2;memory32K
    fr230.excludeAnnotations = base;no_api1_3;api2;memory32K
    fr235.excludeAnnotations = base;no_api1_3;api2;memory32K
    fr630.excludeAnnotations = base;no_api1_3;api2;memory32K
    fr920xt.excludeAnnotations = base;no_api1_3;api2;memory32K
    vivoactive.excludeAnnotations = base;no_api1_3;api2;memory32K
    
    
    ## Configure resource paths for all supported devices with only 16Kb DF memory
    
    d2bravo_titanium.resourcePath = resources;resources-memory16K/resources
    d2bravo.resourcePath = resources;resources-memory16K/resources
    epix.resourcePath = resources;resources-memory16K/resources
    fenix3_hr.resourcePath = resources;resources-memory16K/resources
    fenix3.resourcePath = resources;resources-memory16K/resources
    fr230.resourcePath = resources;resources-memory16K/resources
    fr235.resourcePath = resources;resources-memory16K/resources
    fr630.resourcePath = resources;resources-memory16K/resources
    fr920xt.resourcePath = resources;resources-memory16K/resources
    vivoactive.resourcePath = resources;resources-memory16K/resources
    
    
    ## Configure resource paths for all supported languages for all supported devices with only 16Kb DF memory
    
    # English: No need for English as it's the default language and we don't add resources-eng/strings-settings-memory32K.xml
    # The only reason I added resources-eng is to fix the settings editor bug (sim, GE) to switch to English
    
    ## Hebrew is not supported on these old devices so the files in resources-heb are anyway excluded
    
    # Hungarian
    d2bravo_titanium.lang.hun = resources-memory16K/resources-hun
    d2bravo.lang.hun = resources-memory16K/resources-hun
    epix.lang.hun = resources-memory16K/resources-hun
    fenix3_hr.lang.hun = resources-memory16K/resources-hun
    fenix3.lang.hun = resources-memory16K/resources-hun
    fr230.lang.hun = resources-memory16K/resources-hun
    fr235.lang.hun = resources-memory16K/resources-hun
    fr630.lang.hun = resources-memory16K/resources-hun
    fr920xt.lang.hun = resources-memory16K/resources-hun
    vivoactive.lang.hun = resources-memory16K/resources-hun
    
    # All other languages EXCEPT English and HEBREW are repeated here, similar to Hungarian

    So it intentionally doesn't have the Hebrew for the old devices.

  • And another small bug, which doesn't affect the functionality, but can be improved: the optimized source files includes the comments for not included classes. For example if this is the original file:

    // Comment outside class
    
    (:old)
    class Foo {
      // comment inside old class
      function initialize() {
        // comment inside old class.method
      }
    }
    
    (:new)
    class Foo {
      // comment inside new class
      function initialize() {
        // comment inside new class.method
      }
    }

    then the optimized code for (:old) includes the "// comment inside new class"

    // Comment outside class
    
    (:old)
    class Foo {
      // comment inside old class
      function initialize() {
        // comment inside old class.method
      }
    }
    
      // comment inside new class
        // comment inside new class.method
    

  • Yes, I think this is my bug. I hadn't realized the language list was per-device. I think there's an easy fix.

    Meanwhile you should be able to suppress the warnings by creating a tasks.json entry looking like:

        {
          "type": "omonkeyc",
          "device": "export",
          "compilerWarnings": false,
          "simulatorBuild": false,
          "label": "Export Optimized",
          "group": {
            "kind": "build",
            "isDefault": false
          }
        },

    and then selecting "Export Optimized" from the "Run Task" entry in the command palette (Cmd/Ctrl-Shift-P).

    While trying that, I just noticed another bug though - "compilerWarnings" is incorrectly marked as expecting a string, so you'll get a warning that false is the wrong type in tasks.json. It does seem to work though.

  • The way prettier works, you give it an array of all the comments (with source locations attached), and a separate ast of the code, and it figures out the best node to attach each comment to. So when I delete nodes from the ast, there's no automatic update to the comments list. Since its often hard to know whether a comment belonged to a particular node (does "comment outside class" belong to old-foo, or is it a file header, for example), I just ignored the problem. But clearly, comments entirely contained in a deleted node can safely be deleted. I'll take a look at fixing that...

  • Could you post one (or more) of the problem lines from release.jungle (eg release.jungle:343)?

    The problem isn't quite what I thought. I identified, and have a fix for *a* problem, but (based on what you posted), it doesn't seem to be *your* problem. But the lines in release.jungle that its complaining about should confirm/refute that...