ASTRA Language Support for VS Code
Editor support for the ASTRA agent programming language.
Features
- Outline, breadcrumbs and Go to Symbol in Editor (Cmd/Ctrl+Shift+O): the agent's modules,
types and their formulae, constants, initial beliefs, inference rules, plans, and goals with their own plans
- Go to Symbol in Workspace (Cmd/Ctrl+T): find any plan, goal, formula or agent across the workspace
- Compiler errors as you type: the ASTRA compiler checks open files, including unsaved changes, and reports syntax errors, unknown module actions, undeclared formulas and errors in parent agents in the editor and the Problems view
- Syntax highlighting for
.astra files: keywords, types, FIPA speech acts, built-in list functions, operators, strings, character and numeric literals, and comments. The keyword list follows the ASTRA compiler's token table
- Format Document and format-on-save: consistent indentation using your editor’s tabs/spaces settings, including bracketed continuation lines. Comments, literal contents and existing line breaks are preserved; statements are not reflowed. Formatting works without Java or the language server.
- Comment toggling (
// and /* */)
- Bracket matching, auto-closing pairs, and auto-indentation
- Continuation of
/** */ comment blocks on Enter
- Debugging: breakpoints in
.astra files, stepping through plans, and the agents' variables, beliefs, events and intentions (see Debugging)
- Snippets for agents, plans (goal, belief and message), encapsulated goals, synchronized plans and blocks,
types, module, initial, inference, if/else, while, foreach, try/recover and send
Debugging
Set breakpoints in .astra files, then press F5 (or Debug ASTRA Program in the editor's run menu). The extension runs the project's mvn compile astra:debug (ASTRA 2.8.0 or later), and the program waits for VS Code before it starts.
- Threads are agents. When an agent stops, the others are paused too, so you see the system as it was; continuing resumes them all (set
"stopAll": false to pause only the agent that stopped).
- The call stack is the agent's plans: the plan that stopped, the plans whose subgoals it is working for, and then the agent's other intentions.
- Several intentions: with
"threads": "intentions" in launch.json, each intention is a thread of its own (main / +!work()), so you can select any intention and step it; while it steps, the agent's other intentions wait. With the default "threads": "agents", stepping follows the intention that stopped and the agent's other intentions keep running.
- Step Into goes into the plan of a subgoal (
!g(...)), Step Over runs the subgoal and stops at the next statement, and Step Out stops after the subgoal that adopted the current plan. Other intentions keep running while you step, and stop only at breakpoints.
- Variables: the plan's variables, and the agent's beliefs, events and intentions. Hovering over a variable shows its value.
- Debug console: a variable's name shows its value; a formula, such as
visited(int X, int Y), is queried against the agent's beliefs and shows each answer.
- The program's output appears in the debug console.
A launch.json can name the main agent's class and pass more Maven arguments:
{
"type": "astra",
"request": "launch",
"name": "Debug ASTRA program",
"cwd": "${workspaceFolder}",
"mainClass": "demo.Main",
"mavenArgs": ["-Dastra.name=boss"],
"stopOnEntry": false
}
To debug a program started elsewhere, run it with mvn astra:debug -Dastra.debug.wait=false (it listens on port 4711; -Dastra.debug.port changes that) and use an attach configuration with its port. A program in a container can start the debugger itself when its ASTRA_DEBUG_PORT environment variable is set (with astra-debug's DebugLauncher.startFromEnvironment); forward the port (kubectl port-forward <pod> 4711) and attach to localhost. Breakpoints and frames use your own src/main/astra (sourceRoot).
Rules added at runtime, such as those generated by the planner, open as read-only documents when you step into them, and can have breakpoints while they exist (ASTRA 2.8.1 or later). Agents that declare the Debug module are told when agents stop and resume ($debug.stopped, $debug.resumed), so they can allow for a stopped agent's silence.
Not yet supported: breakpoints in teleo-reactive functions and inference rules, and conditional breakpoints.
Installation
Install from a packaged .vsix file:
code --install-extension astra-<version>.vsix
To build a .vsix from source:
npx @vscode/vsce package
Development
Grammar tests live in tests/ and use vscode-tmgrammar-test. Each line of code is followed by comment lines whose ^ markers assert the scopes of the characters above them:
rule +!main(list args) {
// ^^^^ keyword.other.astra
Excluded scopes (scope - excluded) must be written out in full, e.g. - keyword.other.astra: the runner ignores partial names like - keyword.
Run them with:
npm install
npm test
The language server is a Java program in server/ (built on the ASTRA compiler and LSP4J); the VS Code client that starts it is src/extension.ts. npm run build builds both into dist/ and runs automatically before vsce package, which needs Java and Maven.
npm run test:server: unit tests for the server (Maven)
npm run test:integration: opens a fixture project in a downloaded copy of VS Code and checks the reported errors (needs Node 22+, Java and Maven)
npm run test:debug: debugs a fixture project in a downloaded copy of VS Code: a breakpoint, steps, variables and a query (needs an ASTRA version with astra:debug, see tests/integration/debug-fixture/pom.xml)
npm test runs two checks, both also run in GitLab CI on every push:
test:grammar: the scope assertions in tests/*.test.astra
test:keywords: every keyword in the ASTRA compiler's token table (Token.java) must be highlighted. The token table is read from $ASTRA_TOKEN_JAVA, then ../astra-core, then the develop branch on GitLab
To check the grammar against real ASTRA code, point check:corpus at files or folders. It reads .astra files and ```astra blocks in Markdown, and reports text the grammar leaves unhighlighted and strings or comments that never close:
npm run check:corpus -- ../astra-core ../astra-docs
Requirements
Highlighting and snippets work without anything else installed. Compiler errors, the outline and symbol search need:
- Java 17 or later. The extension uses
astra.java.home if set, then JAVA_HOME, then java on the PATH.
- Maven, for projects with a
pom.xml. The extension runs mvn dependency:build-classpath once (and again when a pom.xml changes) so that module calls are checked against the project's real dependencies. Folders without a pom.xml are checked against the ASTRA 2.4.0 runtime bundled with the extension.
Modules written in Java inside the project are found in target/classes, so run mvn compile after adding or changing them.
To compile and run ASTRA programs see the ASTRA website.
Settings
| Setting |
Default |
Description |
astra.languageServer.enabled |
true |
Check files with the ASTRA compiler as you type |
astra.java.home |
|
Java installation for the language server |
astra.maven.executable |
mvn |
Maven command used to get each project's classpath and to run programs under the debugger |
astra.trace.server |
off |
Log the messages between VS Code and the language server |
Run ASTRA: Restart Language Server from the Command Palette after changing Java modules or if checking stops. The ASTRA Language Server output channel shows which Java and classpath are in use.
Known limitations
- The language server checks files with the ASTRA 2.8.13 compiler, whatever ASTRA version the project uses.
- A workspace with several Maven projects that use different ASTRA versions shares one classpath, so modules resolve against whichever version comes first.
Issues
Please report problems at https://gitlab.com/astra-language/vscode-language-astra/-/issues.
Release Notes
See CHANGELOG.md.
Use Format Document from the editor context menu. To enable formatting on save for ASTRA, add this to your VS Code settings:
"[astra]": {
"editor.defaultFormatter": "remcollier.astra",
"editor.formatOnSave": true
}
JSON values
JSON support requires ASTRA 2.8.13 or later in the project. The extension highlights
json, null and quoted property names, and its bundled compiler checks JSON
literals and variable patterns. Nested objects and arrays retain their structure
when formatting. Snippets: json, module-json, and json-contains.
module astra.lang.JSON J;
rule +!example() {
string city = "Lancaster";
json address = {"City": city, "items": ["apples"], "note": null};
query(J.contains(address, {"City": string result}));
}