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 again have this experience that things like hint, click to go to reference, etc stopped working while I was editing the code. Nothing is red in the explorer tab. But I noticed the following error in the Problems tab:

    Got exception `Got exception `' while processing node $.MyModel.prevNextLetter:VariableDeclarator from MyModel.mc:453:453' while processing node $.MyModel.prevNextLetter:FunctionDeclaration from MyModel.mc:447:460

    [{
    "resource": "/<unknown>",
    "owner": "analysis",
    "severity": 8,
    "message": "Got exception `Got exception `' while processing node $.MyModel.prevNextLetter:VariableDeclarator from MyModel.mc:453:453' while processing node $.MyModel.prevNextLetter:FunctionDeclaration from MyModel.mc:447:460",
    "source": "[pmc-analysis]",
    "startLineNumber": 1,
    "startColumn": 1,
    "endLineNumber": 1,
    "endColumn": 1
    }]

    Looking at the function everything looks ok, no red or yellow signs from the pmc-analysis

    here's my function, not sure it'll be helpful without the context, but maybe:

        hidden function prevNextLetter(d as Number, r as Boolean) as Void {
            var newLI = self.currentLI + d; // Number
            var wL = self.wL; // Number
            if (mHM) {
                var newLMI = getCurrentMI() + d; // Number
                while (0 <= newLI && newLI < wL && self.cM[newLMI] == COLOR_3) {
                    newLI += d;
                    newLMI += d;
                }
            }
            if (0 <= newLI && newLI < wL) {
                self.currentLI = newLI;
                if (r) {
                    WatchUi.requestUpdate();
                }
            }
        }
    

    Update: Something is even stranger than that: even when I comment out all the lines in the function I still get the same error on the same line. There's no way to clear the errors, and it remains there no matter whether I run the app with or without the optimizer.

  • I have what is probably a tall ask, but is there a way to find out the size of a resource before it's loaded? I'm guessing the size is known at compile time, but isn't available at runtime through the standard Monkey C API as far as I can tell. Would it be possible to create a dictionary with a standard name that would have the sizes of the resources and add it to the compiled prg so we could reference it at runtime?

  • I do exactly that but in a python script that generates the resource strings and "BTW" also a dictionary where I can check the size of each one before loading.

    It could be a nice addition to the SDK though. At least for certain types of resources. For strings it should be easy. But for drawables and even jsonData it's not that straightforward IMHO

  • From what I've seen through the simulator strings and jsonData have the same size across all the devices. It's the drawables (and to a lesser extent fonts) I'm particularly interested in for devices pre CIQ 4.

  • Ah, yeah, the old devices... I think 95% of the feature requests are such that would benefit the old devices the most and they are the least likely will ever get it. It's not 0% because the <string id="settingString" scope="settings">This is only used in app settings in Connect IQ or Garmin Express</string> did help, but most other things would need change to the FW and it won't happen. Maybe to middle-old devices like fenix6...

  • But I noticed the following error in the Problems tab

    That's my "last ditch" error handler, for when something completely unexpected happens. I have no idea what caused the error, but I do keep track of which function I last started to process, just so I can report it here.

    Update: Something is even stranger than that: even when I comment out all the lines

    It's probably just that it's not getting cleared from VSCode's list of current problems. If you've deleted those lines, it should definitely go away (or at least changes) if you restart VSCode (or less intrusively, run the "Developer - Reload Window" command).

    I'll see if I can repro using your code - but as you say, it might be hard without the rest of the source.

  • Which is why I was thinking that it would have to be done at the back end like the optimizer which I'm guessing might have access to such info and if so could make it available somehow? Just some wishful thinking. Better yet if there was some algorithm we could use to determine it at runtime based on image size and bits per pixel. I've gathered a bunch of points through the simulator but outliers break the math.

  • leave it. I went back to SDK 6.4.2 and it's gone. Now that I read your comment I tried again with 7.1.0 and it's gone. It must have been some cached thing

  • Which is why I was thinking that it would have to be done at the back end like the optimizer which I'm guessing might have access to such info

    At the moment I try to analyze the resources in order to identify which symbols they make available, and which symbols they reference, but I've not tried to figure out how big they are.

    Figuring out how big the resources themselves are shouldn't be too hard - but for things like layouts that's not really what you want, because its going to read in the resource, and then deserialize it into in memory structures. So you want to know the memory requirements of the various classes involved - some of which could be user defined.

  • I don't know if the size of a bitmap resource is saved with it's symbol at compile time, or the watch figures it out at runtime after it's loaded. You'd think there would be some sort of "load this only if there is enough space instead of dying trying method" but there isn't, so I can understand that the image compiler might not actually bother to save it as such.