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]

  • Sounds great, but unfortunately none of the above features work on this example file:

    const FIRST = 1;
    
    class Test {
        const SECOND = 2;
        hidden var third = 3;
        var fourth = 4;
        var fifth;
    
        function initialize() {
            fifth = FIRST + SECOND + third + fourth;
        }
    }

    Well one works: Ctrl+Click higlights all usages of the same variable that is currently on the screen. But the real things I wanted to have: go to definition, go to references doesn't work :(

  • Also the older features don't work. It looks like you're developing the extension on Mac? Am I right? Because when I did: Ctrl+Shift+P > Prettier Monkey C > Generate Optimized Project , I got the following error:

    Command 'Prettier Monkey C: Generate Optimized Project' resulted in an error (A system error occured (ENOENT: no such file or directory, open '/home/flocsy/Library/Application Support/Garmin/ConnectIQ/current-sdk.cfg'))

    Well /home/flocsy is my Linux home directory, but all the rest doesn't exist and it's not even close to where it should look, because the rest of the path looks like I think it is on Mac (but even there I suppose it depends where you installed it)

    BTW here's my SDK: ~/.Garmin/ConnectIQ/current-sdk.cfg

  • Well, thanks for the feedback!

    So I just tried your code, and it does seem to work for me - although I discovered one issue with my extension. Once its parsed a jungle file, and determined which .mc files belong to the project, adding *new* files won't cause them to be automatically parsed. I obviously need to fix that... but maybe that was the issue? In which case, the fix is to save the jungle file (or modify it in the editor), to cause it to be re-parsed.

    If thats not the problem, can you send me more details of your setup?

  • I don't think that was the issue, because I first tried it on a file that was already in my project before I installed the extension. BTW not sure I understand what that means because my only jungle file looks like this:
    monkey.jungle:

    project.manifest = manifest.xml

    That's it. No referencing of any of the mc files.

  • Yes, I'm developing on Mac, but also testing everything on PC. But I don't have a linux setup to test on.

    Actually, I see the problem. I assume the sdk directory is in the Mac location, *unless* you're running windows, in which case it uses the windows location. And clearly from your SDK path, Linux has yet-another install location. I guess thats the issue... I'll see if I can setup a linux environment...

  • Yes, pretty sure the issue is Linux.

    But what happens is, it parses the jungle, finds all the source files based on that jungle (in the default case, it will just find all the .mc files in the .jungle directory, or any subdirectories). But then those are the only files it watches for changes. Re-saving the jungle file will cause it to search again, and find new files, even though the jungle didn't change.

  • I think you don't necessarily need to. As a default you can add ~/.Garmin/ConnectIQ/ to the list (I assume you're trying to find the current-sdk.cfg file by searching in every place in a list of directories), and since probably Linux is the least used one it can be the last place. A Little more general solution that accomodates custom installs could be to be able to set it in the settings.

  • I can certainly try that, and you can tell me what happens... but experience says that pretty much any different platform is going to have *some* issues.

  • No, nothing changed. And the above Test.mc is a good example, because it intentionally has no use of any Toybox library, so it doesn't really need to know (I guess) where the sdk is...

    Nevertheless if it does then it "forgot" to inform me by a nice error message :)

  • Ok, so I've put a pre-release on the GitHub page that might fix the paths on linux. You can install it via "Install from VSIX" in VSCode's command palette. Let me know if it works. Otherwise I'll set up a linux environment and figure out what needs fixing...