Skip to content

v0.7.0

Latest

Choose a tag to compare

@github-actions github-actions released this 21 Nov 17:52
· 22 commits to main since this release

πŸŽ‰ 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 the import automatically
  • 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 .bal files

πŸ§ͺ 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:Config with groups, dependsOn, dataProvider, before/after, serialExecution, and minPassRate/runs; run or skip groups with --groups, --disable-groups and --list-groups
  • BeforeSuite/AfterSuite, BeforeGroups/AfterGroups and BeforeEach/AfterEach hooks
  • assertEquals, assertExactEquals, assertTrue, assertFail and 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 β€” trap and checkpanic, nested actions, readonly fields 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, trim and case conversion; map:hasKey and get; error:cause; value:clone and toBalString
  • 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-dir for bal pack, bal run and bal build
  • --trace replaces --stats with span-based timing of each compilation stage
  • Release binaries are now also published for windows/arm64, alongside linux/amd64, linux/arm64, darwin/amd64, darwin/arm64, and windows/amd64

πŸ“¦ Projects & packages

  • Ballerina.toml supports icon, readme, exports, module visibility, and includes
  • bal test and bal clean work across every member package of a workspace

πŸ‘‹ New contributors

πŸ”— Resources