Parsware
Alle artikelen

Parsware Platform

The BS editor: signature help and formatting

Open a bracket after a function name and the BS editor shows what the call takes, with the argument you're on in bold and, for a function with several forms, each one to page through. Shift+Alt+F tidies the whole script, keeping your comments and your line breaks. Here is what each one does, and when formatting leaves a script alone.

Dit artikel is alleen in het Engels beschikbaar.

The Course plan script after formatting, with even spacing, indented blocks and braces on their own lines, next to the title "Signature help and formatting"

Two more things the BS editor does while you write a Parsware script. Signature help shows the arguments a function takes as soon as you open its bracket, so you don't have to remember their order. Formatting tidies a whole script with one key.

We used the Course plan command button from BS Lang in ten minutes again: a button on the Training Course list, whose script runs when somebody presses it.

Signature help: what a call takes

A command button can open a view with openView. Type the name and an opening bracket:

The BS editor with openView( typed on line 7 and a hint above it: openView(table: string, view: string), with table: string in bold, and the description Opens a table through one of its views.

The hint shows:

  • the parameters: openView takes a table and a view, both text;
  • the one you're typing now, in bold;
  • a line saying what the function does.

Type the first argument and a comma, and the bold moves to the next parameter:

The same hint after typing openView(table, : now view: string is in bold

The hint stays open while you type an argument, so it's still there when you need to know what comes next. Press Escape to close it. To bring it back inside a call, press Ctrl+Shift+Space.

It works for the host's functions, like openView here, for the methods of a value, such as lines.join(, and for your own functions.

A function with several forms

In BS Lang, two functions can share a name if they take different arguments. The language picks the one that matches the call. Here describe has one form that takes hours, and one that takes hours and a unit:

Two describe functions in the editor, and the hint for describe( showing 1/2 with up and down arrows: describe(hours: int)

1/2 means this is the first of two forms. Press the Down arrow, or click the arrows, to see the other one, describe(hours: int, unit: string). The hint remembers which form you picked while you type the arguments.

Formatting: a tidy script in one key

Scripts get untidy: pasted from somewhere else, written in a hurry, edited by three people. Here is the Course plan script with the spacing and indenting gone:

![The Course plan script typed without spaces or indents: var courses=, {name:'Safety basics',hours:4}, func describe(hours:int):string{, if(hours>=8){ and so on, with a comment at the end of the total line

Press Shift+Alt+F, or right-click in the script and choose Format Document:

The editor's right-click menu with Change All Occurrences, Format Document (Shift+Alt+F), Cut, Copy, Paste and Command Palette

The same script, formatted:

The Course plan script after formatting: spaces around =, : and commas, the if and for blocks indented, each opening brace on its own line, and the comment keep a running total still at the end of its line

What changed:

  • Spacing. One space around =, >= and +=, after : in a type or an object, and after each comma.
  • Indenting. Everything inside a function, an if or a loop is indented one step, and each level inside that one more.
  • Braces. An opening brace goes on its own line, under the line that opens the block.

What didn't:

  • Comments stay. The comment at the top and the one at the end of the total line are exactly where they were.
  • Your line breaks stay. Formatting doesn't join lines or split long ones. The three courses are still on three lines because they were written that way. If you write two statements on one line, they stay on one line, so give each statement its own.
  • What the script does. Formatting only changes spaces and line breaks, never the code itself.

Press Ctrl+Z to undo a format, like any other edit.

A broken script is left alone

Formatting needs to read the script, so it only works on a script without syntax errors. Here the if on line 8 has lost its closing bracket. We pressed Shift+Alt+F and nothing changed:

The untidy script with if(hours>=8{ on line 8 underlined, and one problem: 8:12 missing ')' at '{'. The script is exactly as it was typed

Fix the error in the problems list first (errors as you type), then format.

This is the behaviour now. When we started this article, the formatter did reformat a broken script. The parser works around a syntax error to keep going, and the formatter then rewrote the whole script from that guess, which can move the error and the lines around it. The editor now checks for syntax errors first and leaves the script exactly as you typed it.

Try it

Open any script in a development environment. Type a host function and ( and watch the hint follow your arguments. Then remove a few spaces and indents and press Shift+Alt+F.

Next: the helpers panel, and finding a function without leaving the editor.