Writing Code in TwinBasic: Part 2

Let's explore three more features of the code writing experience in TwinBasic: Code folding, Inline parameter hints, and Outline view.

Writing Code in TwinBasic: Part 2

To learn more about TwinBasic, join me at this year's virtual Access DevCon where I will be presenting this exciting new project from vbWatchdog creator, Wayne Phillips.

In part 1 of this series, I wrote about three features that make TwinBasic's VS Code integration a joy to work with:

  • IntelliSense
  • Go to definition (and peek definition)
  • Semantic highlighting

Let's continue exploring.

Code folding

Code folding allows you to collapse logical portions of your code.  This allows you to pick and choose which parts of your code you want to see on screen at any given time.  You can show the relevant bits and collapse the irrelevant bits out of the way.  It's a great way to increase the signal to noise ratio of your workspace.

Notice the jump in line numbers on the left side indicating that some of our code has been hidden.

I should point out that at this stage of the project, the code folding has not been customized for the TwinBasic language.  Rather, it uses indentation to determine where to begin and end blocks of code.  I would call this "naive code folding" as it ignores the structure of the language itself.

An improvement would be what I'll call "semantic code folding."  In semantic code folding, the development environment groups blocks logically according to the language grammar.  For example, an If statement would mark the start of a code folding block which would continue until it found the matching End If statement.

This sounds simple on its face, but there are challenges in implementing such a system, including nested statements, multiple statements on a single line via the colon operator (:), etc.  Here's to hoping semantic code folding makes an appearance in TwinBasic at some point in the future.

Inline parameter hints

One of the coolest features in TwinBasic's VS Code extension is the inline parameter hints.  This feature lets you toggle the VBA parameter naming syntax on and off without actually changing your code.  Here's an example of how this works:

At the top is our normal code without named parameters; at the bottom, we've toggled the parameter hints on so we can see the name of each parameter.

If you have explicitly named some of the parameters in your code, those are unaffected by toggling the parameter hints on and off:

Parameter hints only appear for unnamed parameters; manually added parameter names are not lost when the hints are toggled off.

Outline view

The final feature I want to talk about is the Outline view.  This is a foldable view of your code grouped by logical sections: modules, routines (functions/subs), custom types, declared variables, etc.

If you click on any of the entries in the list, VS Code takes you straight to that line of code within the editor:

The TwinBasic Outline: more foldable goodness.