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]

  • Have you considered the possibility to introduce new "forcibly enable forbidden post build optimizations" option either in global plugin options or in launch configuration, instead of completely removing them from optimizer's source code as you did for argc? Argc removal can be reverted then.

    This new proposed option can be ignored for building IQ file to always produce package that can be uploaded to the store without alarming security verifier on Garmin's side.

    I think, it's better to have an option to build PRG for side loading at least for personal use instead of having OOM or removing app's functionality to get back these kilobytes that were freed by optimizer.

  • I think, it's better to have an option to build PRG for side loading

    When it was just argc, I didn't think it was worth it. But I think I've finally found all the issues, and I agree with you.

    I'm adding an "allowForbiddenOpts" flag. It will default to false, and it will be forced to false when building an iq file. But if you set it for a simulator or device build, it will re-enable the optimizations I've had to disable...

  • v2.0.93

    Mostly a fix for Build failed if enum value is used in layout which I broke again in v2.0.92

    Someone recently asked about running the optimizer from the command line, so I've also updated the README for @markw65/monkeyc-optimizer to give a simple example of how to use it to optimize projects from the command line.

  • simple example of how to use it to optimize projects from the command line

    Trying it (the only thing I change is the device in buildOptimizedProject call), but

    internal/process/esm_loader.js:74
        internalBinding('errors').triggerUncaughtException(
                                  ^
    
    Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './sdk-util.js' is not defined by "exports" in .../node_modules/@markw65/monkeyc-optimizer/package.json imported from .../optimizer.mjs
        at throwExportsNotFound (internal/modules/esm/resolve.js:299:9)
        // ...
        at link (internal/modules/esm/module_job.js:46:36) {
      code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
    }

    Am I doing something wrong? I have a very limited NodeJS experience.

  • Am I doing something wrong

    Probably not - but maybe there's something in the environment.

    I just tried this on MacOS with node version 18.20.2:

    % mkdir test
    % cd test
    % npm install @markw65/monkeyc-optimizer
    <create test.mjs with the exact contents from the README>
    % node test.mjs ../PowerPod/monkey.jungle
    BUILD SUCCESSFUL
    Built: /path/to/PowerPod/bin/optimized-PowerPod.prg
    Optimized: /path/to/PowerPod/bin/optimized-PowerPod.opt.prg
    

    So it definitely works there. I also tried node-20.5.1.

    I just tried it on windows, with node-20.11.1 and hit a problem - which I need to debug - but I was able to work around it by setting "const workspace = '.';" near the top of test.mjs. The downside is that the bin directory is now created in the current directory (ie where test.mjs is) rather than next to the "monkey.jungle" file.

    So I'll need a bit more information. What platform are you running on, what version of node are you running, and what's in your package.json (specifically "type" and anything relating to modules)?

  • there's something in the environment

    You are right.

    I use ubuntu:22.04 Docker image with NodeJS/NPM from default package repository, that has version 12.22.9. This works fine for installing/updating local optimizer, so I didn't bother to check if I'm using not too ancient version.

    After installing v20.13.1 by NodeSource build finishes successfully.

    My package.json is very basic:

    {
      "name": "...",
      "version": "...",
      "description": "...",
      "author": "...",
      "license": "...",
      "optionalDependencies": {
        "prettier": "^2.8.8"
      },
      "dependencies": {
        "@markw65/monkeyc-optimizer": "^1.1.63"
      }
    }
    

    Thank you!

  • https://github.com/markw65/monkeyc-optimizer/blob/main/src/optimizer.ts#L137-L142

    Could this be improved to get settings from "code-workspace" file too? I don't know how to get its name and location without VS Code API though.

  • That makes sense, I'll update the README (I think 16.x is the minimum requirement).

    Just a note, and this doesn't really matter unless you're going to build and publish your package, but you almost certainly want @markw65/monkeyc-optimizer to be in devDependencies, rather than dependencies (the -D in "npm install -D @markw65/monkeyc-optimizer" would do this for you).

    dependencies are things that need to be shipped along with your project, while devDependencies are things that are used during the build of your project.

  • I suppose I could add a codeWorkspace option, and use that if specified.

    But yes, its not clear how you would, in general, find the code-workspace from the location of the jungle file. I could look in the folder containing the .jungle file, and all its parents (and then check that the folder containing the jungle is one of the workspaces in the code-workspace file).

    That would actually fail for the only code-workspace I use, because the code-workspace file is in a sibling of the folder containing all the monkeyc projects - but I think that's probably an unusual setup.

    I should probably also update it to read all the relevant options. I think I stopped adding new options there a long time ago, because the extension takes care of passing them in explicitly.