Repository navigation
π Milestone 7 Release: Ballerina Nutcracker
This milestone brings Ballerina to your editor with the first language server, and adds a test framework (bal test), compiler plugins, language subset 10, and standard library subset 3 with ten new modules.
π‘ Language server
bal now ships a language server that speaks the Language Server Protocol (LSP 3.18) over stdio, so any LSP-capable editor can use it. Editors start it with:
bal start-language-server
- Diagnostics as you type β syntax and semantic errors are published as you edit, using incremental document sync; only the modules affected by a change are recompiled, in the background
- Code completion β keywords, variables and functions in scope, and enum members; context-aware snippets for module-level definitions and statements; initializer suggestions ranked by the expected type; in type positions, types from imported and bundled standard library modules after their prefix (e.g.
time:), adding theimportautomatically - Signature help β parameter hints triggered on
(and,, with the highlighted active parameter and the function's documentation - Projects and single files β works on packages with multiple modules, resolving their dependencies, and on standalone
.balfiles
π§ͺ Testing
The new bal test command, together with the ballerina/test module, runs tests for a package, a standalone .bal file, or every package in a workspace:
import ballerina/test;
@test:Config {}
function testAdd() {
test:assertEquals(add(2, 3), 5);
}$ bal test
Running Tests
demo
[pass] testAdd
1 passing
0 failing
0 skipped
@test:Configwithgroups,dependsOn,dataProvider,before/after,serialExecution, andminPassRate/runs; run or skip groups with--groups,--disable-groupsand--list-groupsBeforeSuite/AfterSuite,BeforeGroups/AfterGroupsandBeforeEach/AfterEachhooksassertEquals,assertExactEquals,assertTrue,assertFailand their negations
Not in this cut: mocking and code coverage (
--code-coverage) are not supported yet.
π Language features (subset 10)
Concurrency β named workers, and the start and wait actions:
function compute() returns int {
worker A returns int {
return 20;
}
worker B returns int {
return 22;
}
int a = wait A;
int b = wait B;
return a + b;
}
function square(int n) returns int => n * n;
public function main() {
future<int> f = start square(7);
int sq = checkpanic wait f;
io:println(compute(), " ", sq); // 42 49
}Expressions β conditional expressions, shorthand and spread fields in mapping constructors, lax field access on json, and foreach over strings:
Point p = {x, y}; // shorthand fields
Point3D q = {...p, z: 3}; // spread field
string size = q.z > 2 ? "deep" : "flat"; // conditional expression
json payload = {user: {name: "Ann"}};
json name = check payload.user.name; // lax field access on json
foreach string:Char c in "abc" {
io:print(c, " ");
}XML β step and filter expressions for navigating XML:
xml doc = xml `<root><item>a</item><note>n</note><item>b</item></root>`;
io:println(doc/<item>); // <item>a</item><item>b</item>
io:println(doc.<root>);Also in subset 10:
- Expressions β
trapandcheckpanic, nested actions,readonlyfields in mapping constructors, defaults from the detail record in error constructors - Functions β named and default arguments in more call forms, including
var-declared function values, included record parameters on methods, and dependently typed resource methods and array return types - Annotations β annotations on service remote methods, and service, parameter and record field annotations available at runtime
- Language libraries β the rest of
lang.xml;array:toStream;string:includes,indexOf,substring,trimand case conversion;map:hasKeyandget;error:cause;value:cloneandtoBalString - Spec deviations β intentional differences from the language specification are now documented in the subset doc
π Compiler plugins
Packages can now run compiler plugins declared in CompilerPlugin.toml. The plugins of each package a module imports run as part of compilation. ballerina/test uses this to discover tests.
π Standard library (subset 3)
Ten new modules, plus major additions to io and http:
| Module | What it covers |
|---|---|
avro |
Avro binary serialization and deserialization driven by a schema |
file |
File and directory operations, and a directory listener |
ldap |
A client for reading and modifying entries on an LDAP directory server |
mime |
MIME media types, entities, and multipart bodies |
mqtt |
An MQTT v5 client and listener |
protobuf |
Protobuf well-known types used by generated gRPC code |
task |
One-time and recurring job scheduling |
test |
Annotations, configuration, and assertions for bal test |
udp |
UDP clients and a UDP listener |
uuid |
RFC 4122 UUID generation, validation, and conversion |
io |
Stream-based file read/write, and byte, character and data channels |
http |
Client response data binding, client resource access (client->/albums/[id]), XML payloads, anydata resource returns, and MIME support |
import ballerina/avro;
import ballerina/io;
import ballerina/uuid;
type Person record {
string name;
int age;
};
public function main() returns error? {
avro:Schema schema = check new (string `{
"type": "record", "name": "Person",
"fields": [{"name": "name", "type": "string"}, {"name": "age", "type": "int"}]
}`);
byte[] encoded = check schema.toAvro({name: "Ann", age: 30});
Person person = check schema.fromAvro(encoded);
io:println(person);
io:println(uuid:validate(uuid:createType4AsString()));
}π οΈ CLI & tooling
| Command | Description |
|---|---|
bal test [<source-file.bal> | <package-dir>] |
Run package tests |
bal add <module-name> |
Add a new module to the current package (lib or service template) |
bal push [<bala-path>] --repository=local |
Push a package's .bala to the local repository |
bal clean [<package-dir>] |
Delete the build artifacts in target |
--target-dirforbal pack,bal runandbal build--tracereplaces--statswith span-based timing of each compilation stage- Release binaries are now also published for
windows/arm64, alongsidelinux/amd64,linux/arm64,darwin/amd64,darwin/arm64, andwindows/amd64
π¦ Projects & packages
Ballerina.tomlsupportsicon,readme,exports, module visibility, andincludesbal testandbal cleanwork across every member package of a workspace
π New contributors
- @oshankkkk made their first contribution in #934
- @nipunayf made their first contribution in #1421