Question
Julian Matthews · Nov 3

Reformatting ObjectScript in VSCode

Hey everyone.

I was wondering if anyone had come across a way of reformatting ObjectScript within VSCode.

I have the various Intersystems Extensions installed (InterSystems Language Pack,  InterSystems ObjectScript,  InterSystems ObjectScript Extension Pack,  InterSystems Server Manager) but a formatter does not seem to be something included within this variety of extensions.

00
4 0 16 168
Log in or sign up to continue

what sort of reformatting are you looking to do?  Like command expansion that Studio offers or something else?  

Hey Ben.

Specifically looking to be able reformat the code layout. For example, if I was working with javascript or json, I can use the keyboard command Shift+Alt+F and it will reformat the code:

However, when I attempt this with the language set to ObjectScript or ObjectScript-Class, pressing that same keyboard shortcut gives a popup stating no formatter is installed and it directs me to the Extension Marketplace

Do you look for something like <CTRL>E in Studio ?

@Julian Matthews The Language Server extension includes an ObjectScript formatter with the following features:

  • Normalize the case of ObjectScript commands, system functions and system variables.
  • Normalize the usage of short or long versions of ObjectScript commands, system functions and system variables.

You can invoke it like any other formatter in VS Code. This VS Code doc page has more information on formatting in VS Code. The Language Server README has more info on its features and configuration settings.

Hey @Brett Saviano 
I have the Language Server extension installed, however invoking the formatter using the keyboard shortcut Shift+Alt+F ( as per the VSCode documentation you linked) gives this popup:

Hi Julian,

I just opened up my VS Code (version 1.61.2 on Mac, latest version of all 3 extensions) and tried formatting a class and mac routine and it worked both times. Can you confirm that the Language Server extension is enabled? Also, what's the extension of the file that you're trying to format?

Hey Brett, thank you for your help.

I have found the issue.

It looks like a file needs to be saved as a .cls first before the formatter is available for use. This differs from other languages within VSCode which just needs the language to be set for the new document.

Yes, that's expected behavior. The vscode-objectscript extension defines the languages based on file extensions:

      {
        "id": "objectscript",
        "aliases": [
          "ObjectScript"
        ],
        "extensions": [
          ".mac",
          ".int"
        ]
      },
      {
        "id": "objectscript-class",
        "aliases": [
          "ObjectScript Class"
        ],
        "extensions": [
          ".cls"
        ]
      },
      {
        "id": "objectscript-macros",
        "aliases": [
          "ObjectScript Include"
        ],
        "extensions": [
          ".inc"
        ]
      },
      {
        "id": "objectscript-csp",
        "aliases": [
          "ObjectScript CSP"
        ],
        "extensions": [
          ".csp",
          ".csr"
        ]
      },

@Julian Matthews - Off-topic  question:  Your screen-capture snippets really helped to quickly illustrate your issue as well as the solution once you found it.  This is an incredibly effective way to communicate - what tool to you use to capture these?  

Hey Ben.

I use a program called ScreenToGif.

Since moving to remote working it has become invaluable for demonstrating functionality for apps via email or IM. However it gets the most use when I'm reporting bugs to a supplier, or in this case how I'm incorrectly using VSCode extensions smiley

I'm pretty sure it's a Windows-only app, so you may need to find an alt if you're on another OS and wish to try it out.

*edit*

As a tip, try to keep any gifs you do make for bug reporting fairly short. No one wants to be waiting 2 minutes for a gif to loop because they missed the important part!

Thank you @Julian Matthews !!  Installed and I look forward to using it and sharing with others as well.  Much appreciated :)

A Super Tool. I wish I had it in past already
Thanks for posting 

Thanks John, that's very good to know about.

It's missing 1 or 2 features I like in ScreenToGif, but it's certainly going in my bookmark bar.