Question Julian Matthews · Nov 3, 2021

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.

Comments

Ben Spead · Nov 3, 2021

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

0
Julian Matthews  Nov 3, 2021 to Ben Spead

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

0
Michael Richards  Apr 18, 2024 to Julian Matthews

Hey, did you ever find a solution for this? I was able to get the auto formatter working but it looks like it only handles variables and class names.

0
Robert Cemper · Nov 3, 2021

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

0
Brett Saviano · Nov 3, 2021

@Julian.Matthews7786 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.

0
Julian Matthews  Nov 3, 2021 to Brett Saviano

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:

0
Brett Saviano  Nov 3, 2021 to Julian Matthews

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?

0
Julian Matthews  Nov 3, 2021 to Brett Saviano

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.

0
Brett Saviano  Nov 3, 2021 to Julian Matthews

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"
        ]
      },
0
Ben Spead  Nov 3, 2021 to Julian Matthews

@Julian.Matthews7786 - 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?  

0
Julian Matthews  Nov 3, 2021 to Ben Spead

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!

0
Ben Spead  Nov 3, 2021 to Julian Matthews

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

0
Robert Cemper  Nov 3, 2021 to Julian Matthews

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

0
Ben Spead  Nov 3, 2021 to Robert Cemper

I completely agree @Robert Cemper - already found a use for it on my team today :)

0
Julian Matthews  Nov 4, 2021 to John Murray

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.

0
Kwabena Ayim-Aboagye · Jun 26, 2024

Has there been headway in formatting longer lines of ObjectScript? Example:

Relationship PhoneNumbers As isc.sample.rest.phonebook.model.PhoneNumber(%JSONFIELDNAME = "phones", %JSONINCLUDE = "outputonly", %JSONREFERENCE = "object") [ Cardinality = children, Inverse = Person ];

I prefer lists of parameters to be visible in one view rather than having to scroll across the screen. I think it would be better if this were added to the existing functionality rather than me writing my own script to format ObjectScript code in this manner. 

0
Brett Saviano  Jun 27, 2024 to Kwabena Ayim-Aboagye

@KwabsNo, there hasn't. Even if we had formatting for your specific example, the extra newlines would be erased when the document gets saved on the server. The only code in class definitions that's preserved as-is is implementation code enclosed in curly braces. The rest is stored in a global and regenerated from the global after a save.

0