# Roomle Component Formatter

Includes JSON escaper/unescaper, which provides a possibility to replace /n with //n and vice-versa. This allows to have multiline value JSONs but still be able to use code prettifiers, schemas etc.

# Download

Get it under this link: rmlformatter-0.4.2.vsix

# Features

# Multiline JSON Escaper:

Takes

{
    "key": " multiline
    string
    in 
    json
    value
    "
}

and makes it to:

{
    "key": " multiline\n    string\n    in \n    json\n    value\n    "
}

and back.

# Roomle Script Formatter:

  • A strict formatter supporting Roomle Script
  • Rules:
    • Indentation: 4 spaces
    • Indentation reasons:
      • { and }
      • BeginObjGroup() and EndObjGroup()
      • geometry modifier functions (move, rotate and set material) indent by 1 space
    • Exactly one spaces around operators, one behind commas and semicolons
    • No spaces around ( and ) except 'for (' and 'if ('
    • No trailing spaces, empty have no spaces
    • Multiline string ends with closing quote at the level of next JSON attribute
    • Ignores string values (= characters between apostrophes)

# Roomle Script Autocomplete:

  • On autcomoplete feed call, it inserts following entries into the autocomplete list:
    • parameter keys
      • along with parameter keys, it also lists the possible values in the documentation area of the VS Code's Autocomplete
    • superseding keys
    • internal variables
      • this is done by RegEx search for structures of: [a-zA-Z0-9_.]*\s=\s (some.thing space = space)
      • not yet context aware (everything is available everywhere)

# Requirements

JSON keys and values delimiter character must be quote "

There can't be quote characters inside values, even "

No other extensions required.

# Extension Settings

# Known Issues

  • Ignores commented parts of the code
  • On document open, the event is not called reliably to feed the autocomlete. Sometimes, you need to do it yourself. This should be however much better since 0.4.2
  • While mass formatting all open JSONs, pressing the stop formatting button does not help when a script is too big making the configurator stuck.

# Release Notes

# 0.4.2

  • Fixed a bug, where validValues of valueObject values of type string (from Json perspective <=> values without quotes) did not enter autocomplete.
  • Autocomplete now also suggests values of parameters with validValues or valueObjects.
  • On document open, the event is not called reliably to feed the autocomlete. Sometimes, you need to do it yourself.
  • Added better error path. Up to now, only index in the JSON list was shown in the error path. Now, it also shows parameter's key, subComponent's internalId and connection's mask behind a colon, which should make scripts with errors much easier to find in big component definitions.
  • Implemented parameter table generation.
    • Usage: #TABLE parameter1Ket, parameter2Key and then let format
    • This will prescribe an if-structure of all validValues and valueObjects in a parameter. Parameters require validValues or valueObjects for this feature to generate the table.
  • While formatting mutliple JSONs, buttons leading to formatter functions are hidden and a button "STOP MASS FORMATTING" is shown instead, allowing you to stop formatting in the process. However, it does not stop formatting of a current script, which is a known error. If the script is too big or makes the formatter stuck, you still need to restart VS Code.

# 0.4.1

  • Implemented support for formatting component.label script
  • Introduced VS Code command Format All Open Roomle JSONs
    • Allows you to mass-format the open tabs with JSON scripts
    • Usage:
      1. I recommend closing all open tabs first
      2. in the file explorer, select the files you want to open and select "Open to Side" from the right-click context menu
      3. invoke command menu with Ctrl+Shift+P and rum the command
      4. wait until the formatter runs through all open tabs
      5. after formatting, the scripts are not saved, do it yourself by selecting File > Save All, you can also close all tabs by right clicking the tab and select Close others or other options

# 0.4.0

  • Introduced the autocomplete function for parameters, variables and supersedings has been implemented

This is a prototype autoformatting. The principle is that it feeds parameteres and supersedings keys and then regex searches the whole JSON file on something = and feeds something into the autocomplete list. Context in which RoomleScript you are at the moment of typing is not being wathced.

Autocomplete feeding is ran on document open, tab change and after formatting the code using Alt+Shift+F. If it fails for any reason, you can still use the RML-Format. Keep in mind, that it does not (yet) dynamically update the autocomplete list during typing.

# 0.3.4

  • Formatting is now applied also on assignments
  • Fixed failure on packaging conditions
  • Fixed inline else {_... did not retain the marked line

# 0.3.3

  • Fixed error where multiline comments lost their spaces

# 0.3.2

  • Renamed extension name (uninstall previous version first!)
  • Added hotkey Shift+Alt+F to run the formatter
  • Discovers following errors:
    • non-matchning /* */
  • Excessive closing bracket error displays a line number only with the first occurence of the error. Excessive opening bracket can not be detected until end of script. The formatter will go on so that the bracket error can be more easily discovered.
  • Odd apostrophe will terminate the formatter and display a line number with the error.
  • Fixed error when replacing // with /* */

# 0.3.1

  • Formatting tweaks
  • Added functionality to discover following errors:
    • mismatch of count in opening and closing indentation reasons (shows which script)
    • unclosed string apostrophe (shows which script and which line)
    • keeps normalized numbers (format 1.23e-0045)

# 0.3.0

  • Optimized and reafactored formatter
  • Improved stability
  • Reduced strictness of formatting

# 0.2.4

  • Fixed bug where the formatter would return with no result if a script with multiple empty lines was present
  • Fixed incorrectly formatted trailing // style single line comments

# 0.2.3

  • Fixed Windows line end style errors
  • Formatter now formats negative numbers as -1 instead of - 1
  • Formatter now formats correctly ++ and -- operators
  • Stability fixes
  • Fixed an error where some one-line right-side expression incorrectly went to more lines
  • Trimmed empty newlines at start & end of multiline scripts

# 0.2.2

  • Fixes to the formatter
  • Applies to most scripts in the JSON file structure

# 0.2.1

  • New formatter rules:
    • keeps max. 2 empty lines
    • keeps inline expressions separated by semicolon
    • keeps single-line script
    • converts // comments to /* */

# 0.2.0

  • Prototype code indenter, added status bar buttons

# 0.1.4

  • Internal improvements

# 0.1.3

  • Fixed line-ends for Windows

# 0.1.2

  • Internal algorithm change.

# 0.1.1

  • Fixed an error that lost the last character in affected string values in certain situations and made the functionality mroe robust.

  • Count of affected lines now works correctly.

# 0.1.0

  • Initial release