Flex for VS Code
Flex is an open, typed specification language for software architecture. A specification names the
components of a system, the messages they exchange, and the protocols that put those exchanges in
order. It is precise enough to be checked formally, and structured so that changing it tells you what
else has to change.
This extension adds Flex to VS Code: highlighting, diagnostics as you type, project-wide navigation,
and completion.
The language in brief
Start with the data and the parts that exchange it.
module hvac.control
message struct SetPoint { celsius: float32; }
message struct Ack {}
message struct Fault { code: uint16; }
component Thermostat;
component Furnace;
connection Control from Thermostat to Furnace;
A protocol says what happens, and in what order. Here the thermostat sends a set point, and the
furnace answers with either an acknowledgement or a fault.
global protocol Adjust {
exch any SetPoint into let target: SetPoint from Thermostat to Furnace on Control;
choice in Furnace
| true => exch any Ack from Furnace to Thermostat;
| else => exch any Fault from Furnace to Thermostat;
end
}
exch is one exchange between two components. into let binds the message, so later steps can refer
to its fields. choice in Furnace records which component decides the branch — worth stating
explicitly, because everyone else has to be able to tell the branches apart. Protocols can also run
branches concurrently with parallel, loop, and be written from a single component's point of view
as a local protocol built from send and recv.
The payoff arrives when the design changes. Add a field to Fault, rename SetPoint, or move
Control to a different pair of components, and the places that no longer fit show up as
diagnostics instead of as a search through the tree.
In the editor
- Errors and warnings on open and as you type, over every
.flex file in the workspace rather than
just the open buffer.
- Go to definition, find all references, and rename, each of them project-wide and following
import across files.
- Hover for the inferred type and the reconstructed declaration at the cursor.
- Completion of the names that are in scope where you are typing.
- Outline and breadcrumbs for a file; symbol search across the workspace.
- A TextMate grammar for immediate coloring, with semantic highlighting from the server layered over
it once analysis completes.
- Module paths in
import rendered as links, so they are Ctrl- or Cmd-clickable.
Getting started
Install the extension, then open a folder that contains .flex files. The language server is bundled
in the extension, so there is no separate download and no toolchain to set up.
Analysis covers the whole workspace, not one file at a time, so imports and cross-file references
resolve from the first keystroke. Everything runs on your machine.
Leaving files out
Every .flex file under a workspace root belongs to the project by default. If a tree also holds
build output or fixtures you would rather not see in the problems list, put a .flexignore at the
workspace root:
target/ # a directory of this name, at any depth
generated/*.flex # a glob inside one path segment
/vendor/ # a leading slash anchors the pattern to the root
A pattern ending in / matches directories only; one without a slash matches a basename at any
depth; one containing a slash is anchored to the root. With no .flexignore, nothing is excluded.
Settings
| Setting |
Effect |
flex.server.path |
Absolute path to a flex-lsp binary to run instead of the bundled one. Leave empty to use the bundled server. |
flex.trace.server |
Log JSON-RPC traffic to the Flex Language Server output channel: off, messages, or verbose. |
The output channel also reports which server binary was chosen, which is the first thing to check if
the extension seems inactive.
License and notices
Use of this extension is governed by the FlexLang Visual Studio Code Extension Free License
Agreement, included in the package as LICENSE.txt. Attribution for the open source components the
extension bundles is in THIRD-PARTY-NOTICES.txt.
More
Language documentation and reference: https://flexlang.org/
Questions, bug reports, and security reports: support@tangramflex.com