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]

  • That's odd - it's working perfectly for me. I *have* seen strange issues sometimes when I upgrade from one version of monkeyc-optimizer to another, and I have to restart VSCode to get things going again. I assume VSCode is doing some caching. Is it possible that you had an earlier version installed (eg to use the font decoder)?

    In any case, can you try restarting VSCode? Beyond that, I'm at a loss, but if you have a full stack trace, I suppose it might help.

  • Hi, could you, please, make it possible to run optimizer from the command line?

  • restarted, but the same:

     *  Executing task: omonkeyc: fr230 
    
    Starting optimization step...
    Using project-local @markw65/[email protected]
    ERROR: Internal: TypeError [ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING]: A dynamic import callback was not specified.
    TypeError: A dynamic import callback was not specified.
            at new NodeError (node:internal/errors:405:5)
            at importModuleDynamicallyCallback (node:internal/process/esm_loader:39:9)
            at Object.<anonymous> (/Users/me/MyApp/node_modules/prettier/index.cjs:593:23)
            at o._compile (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/loader.js:4:1271)
            at Object..js (node:internal/modules/cjs/loader:1326:10)
            at Module.load (node:internal/modules/cjs/loader:1126:32)
            at node:internal/modules/cjs/loader:967:12
            at Function.<anonymous> (node:electron/js2c/node_init:2:13357)
            at h._load (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:173:5634)
            at n._load (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:170:29786)
            at t._load (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:135:35289)
            at Module.require (node:internal/modules/cjs/loader:1150:19)
            at h (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/loader.js:4:647)
            at Object.<anonymous> (/Users/me/MyApp/node_modules/@markw65/prettier-plugin-monkeyc/build/prettier-plugin-monkeyc.cjs:15:48299)
            at o._compile (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/loader.js:4:1271)
            at Object..js (node:internal/modules/cjs/loader:1326:10)
            at Module.load (node:internal/modules/cjs/loader:1126:32)
            at node:internal/modules/cjs/loader:967:12
            at Function.<anonymous> (node:electron/js2c/node_init:2:13357)
            at h._load (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:173:5634)
            at n._load (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:170:29786)
            at t._load (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:135:35289)
            at Module.require (node:internal/modules/cjs/loader:1150:19)
            at h (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/loader.js:4:647)
            at Object.<anonymous> (/Users/me/MyApp/node_modules/@markw65/monkeyc-optimizer/build/chunk-MBTLUWXR.cjs:41:38)
            at o._compile (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/loader.js:4:1271)
            at Object..js (node:internal/modules/cjs/loader:1326:10)
            at Module.load (node:internal/modules/cjs/loader:1126:32)
            at node:internal/modules/cjs/loader:967:12
            at Function.<anonymous> (node:electron/js2c/node_init:2:13357)
            at h._load (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:173:5634)
            at n._load (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:170:29786)
            at t._load (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:135:35289)
            at Module.require (node:internal/modules/cjs/loader:1150:19)
            at h (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/loader.js:4:647)
            at Object.<anonymous> (/Users/me/MyApp/node_modules/@markw65/monkeyc-optimizer/build/chunk-J5XJWBYV.cjs:138:29)
            at o._compile (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/loader.js:4:1271)
            at Object..js (node:internal/modules/cjs/loader:1326:10)
            at Module.load (node:internal/modules/cjs/loader:1126:32)
            at node:internal/modules/cjs/loader:967:12
            at Function.<anonymous> (node:electron/js2c/node_init:2:13357)
            at h._load (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:173:5634)
            at n._load (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:170:29786)
            at t._load (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:135:35289)
            at Module.require (node:internal/modules/cjs/loader:1150:19)
            at h (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/loader.js:4:647)
            at Object.<anonymous> (/Users/me/MyApp/node_modules/@markw65/monkeyc-optimizer/build/optimizer.cjs:38:29)
            at o._compile (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/loader.js:4:1271)
            at Object..js (node:internal/modules/cjs/loader:1326:10)
            at Module.load (node:internal/modules/cjs/loader:1126:32)
            at node:internal/modules/cjs/loader:967:12
            at Function.<anonymous> (node:electron/js2c/node_init:2:13357)
            at h._load (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:173:5634)
            at n._load (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:170:29786)
            at t._load (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:135:35289)
            at Module.require (node:internal/modules/cjs/loader:1150:19)
            at h (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/loader.js:4:647)
            at /Users/me/.vscode/extensions/markw65.prettier-extension-monkeyc-2.0.81/build/extension.js:11:27102
    
     *  The terminal process failed to launch (exit code: 1). 
     *  Terminal will be reused by tasks, press any key to close it. 

  • I think it's the prettier formatter that's causing the problem. Version 3 made big changes to the api; I did fix things to work with v3 when it first came out, but stuck with v2 because the vscode prettier extension (as in the formatter, not my optimizer) still uses v2 internally. But something else must have changed and it no longer works with v3.

    And it turns out that a new installation of @markw65/monkeyc-optimizer pulls in prettier-3.x by default (I'll fix that if I can't make it work with v3).

    Anyway, if I install v3, I can repro (so I'll debug), but you can fix the problem by "npm install -D [email protected]".

    You will definitely have to restart VSCode after doing that before it will work.

  • It already is possible, but you would need a javascript wrapper to invoke it. I can document the api, and maybe include a small wrapper in the package.

    If you want to see an example, look at src/driver.ts. It's what I use to run all my tests (invoked via test/test.js). There's a lot of code, but thats mostly because it has a lot of command line options, and a lot of special handling for particular tests.

  • OK, with [email protected] it seems to work. Did a "Export Optimized Project" with SDK 6.4.2 and with 7.1.0 as well.

    I noticed something though, and I'll be honest I never looked at this, so maybe it was like this all the time, maybe it's something new: When I run "Build and Run Optimized - Release" I can see the output of the post build optimizer. However when I do the export optimized project then I don't see it. Either the post optimizer doesn't run or it doesn't log much information. I can only see this short line at the very end:

    > Optimizing MyApp.original.iq to MyApp.iq (Using project-local @markw65/[email protected]) <

    With no indication of the "gain".

  • OK, with [email protected] it seems to work

    Good. There are a few other small issues I'm going to try to address, but I should get another release out today or tomorrow.

    With no indication of the "gain"

    That's always been the behavior. I guess that's something I can add, but its going to be very noisy...

  • Actually the "regular" output (of single build) is also a bit noisy:

    > Sizes for optimized-MyApp.original-fr955: code: 17612 data: 7308 <
    
    
    > Optimizing optimized-MyApp.original.prg to optimized-MyApp.prg (Using project-local @markw65/[email protected]) <
    
    
    > Sizes for optimized-MyApp-fr955: code: 17238 data: 7308 <
    

    I never understood why are there 4 empty lines and the middle line. I think it could all be fit into 1 line:

    > Sizes: optimized-MyApp.original-fr955: code: 17612 data: 7308, optimized-MyApp-fr955: code: 17238 data: 7308 <

    And for the "export project" I don't know if it's possible (probably not, because all the build between the source code optimization to the post build optimization is done by 1 call to the compiler?) you could also add the same line after each and every device prg.

  • I never understood why are there 4 empty lines and the middle line.

    The middle line is just because most tools show you what they're doing - eg there's no need for Garmin's compiler to print out its command line, but it does.

    The extra spacing is just because there is often a lot of output, and spreading this out makes it easier to spot.

  • With no indication of the "gain"

    Just FYI there's a lot of optional logging available - mostly to help me debug. You can turn on per ".prg" stats via MC_LOGGER=bytecode. To do so, quit VSCode, then from the command line run 

    MC_LOGGER=bytecode code

    This assumes that "code" ie VSCode is on your path - if not, there's a VSCode command to do so. Cmd-P - "SHELL command install 'code' in PATH"

    Once you've done that you can open the developer tools window (Help->Toggle Developer Tools), and when the post build optimizer runs, it will spit out a line like

    MyProgram.original.prg: code size: 2779 => 2564 difference: 215

    If you build a .iq file, it will spit out one line per product:

    006-B4305-00/MyProgram.original.prg: code size: 2779 => 2564 difference: 215
    006-B3843-00/MyProgram.original.prg: code size: 2779 => 2564 difference: 215
    006-B3111-00/MyProgram.original.prg: code size: 2779 => 2564 difference: 215
    006-B3135-00/MyProgram.original.prg: code size: 2779 => 2564 difference: 215