accentlang for VS Code
Standard IDE support for the Accent programming language in VS Code.
Features
Ordered by day-to-day developer usefulness:
- Diagnostics: Parser and semantic diagnostics from the Accent compiler frontend.
- Navigation and completion: Completion, hover information, and jump-to-definition through the language server.
- Syntax highlighting: Java-shaped declarations, explicit visibility, interpolated strings, HTML components,
async / await, and visible ? / ?? contracts.
- Formatting: Document and selection formatting adapted from Accenture Java Formatter, with four-space blocks, two-space continuations, multiline calls, and import organization. Preserves Accent templates and literal contents.
- Generated Java command: The extension registers Accent: Show Generated Java, backed by the server's transpile command. The CLI's
--save-java output is also available for inspecting generated Java.
The extension includes an Accent formatter adapted from Accenture Java Formatter 0.9.8. It runs locally in VS Code without Java or a language server.
Use Format Document, Format Selection, or Accent: Organize Imports. Ctrl+Alt+L (Cmd+Option+L on macOS) formats the active Accent document. This extension is the default formatter for Accent unless your editor settings override it.
The default style uses four-space blocks and independent two-space continuations. Calls and declarations with multiple arguments put one argument on each line. Nested calls and method chains wrap, annotations get their own lines, and extends, implements, and throws start continuation lines. The preferred line width is 70 columns; long literals and comments are not split.
For example:
this.service.send(
first,
second);
Enable standard VS Code format-on-save and customize the style in Settings:
{
"[accent]": {
"editor.defaultFormatter": "LemuelAdane.accentlang",
"editor.formatOnSave": true,
"editor.tabSize": 4,
"editor.insertSpaces": true
},
"accent.format.continuationIndent": 2,
"accent.format.maxLineLength": 70,
"accent.format.organizeImports": true,
"accent.format.braceStyle": "sameLine"
}
accent.format.tabSize and accent.format.insertSpaces can override the editor's indentation settings; when unset, the editor settings apply. Set accent.format.enabled to false to disable document and selection formatting.
Run npm run test:e2e to exercise formatting in a VS Code extension host. It requires a graphical display and uses /usr/share/code/code by default; set VSCODE_EXECUTABLE to the VS Code executable when it is installed elsewhere.
The formatter preserves ? / ?? contracts, optional access, then / else, async / await, and bodyless record/model declarations. Strings, interpolated strings, backtick templates (including SQL and HTML), text blocks, and comments keep their contents. Selection formatting expands to complete selected lines and leaves partial multiline literals/comments untouched.
Conditional then/else branches start continuation lines; nested branches indent by an additional continuation step at each nesting level. Null-fallback else remains distinct from conditional branches. Logical and/or operators start continuation lines so each condition is on its own line.
Import organization sorts and deduplicates plain contiguous import groups. Comments and annotated import lines stay in place; unused imports are not removed. Java-specific ternary rewrites and Eclipse XML profiles are not applied to Accent. See third-party notices for attribution.
Console output and logging
Use print(...) or println(...) without System.out. An automatic log binding provides severity and diagnostic-context methods without an import or @Logging. log("message") calls static Logger.log("message") at INFO, even with a local variable named log; log.error("message", exception) selects ERROR. Logger is an implicitly available class; new Logger() creates an instance named after the calling class.
println("Hello, Accent!");
log("Started");
final log = new Logger();
log.put("requestId", "R1");
try {
log.info("Processing request");
} finally {
log.clear();
}
Completion offers print, println, log, and Logger; log. includes logging and context methods. Generated Java previews expand these shorthands. User-defined members still require this., super., or static. as appropriate; bare printing and logging calls select built-ins.
Visibility
| Accent modifier |
Java output |
Access |
public |
public |
Public |
protected |
protected |
Same package and subclasses, following Java protected-access rules |
private |
No visibility modifier |
Same package only |
Protected and private declarations require an underscore prefix (protected int _step, private int _cache). The modifier determines access; an underscore is a visual marker. Members without a modifier are public, even if their names begin with _ or __. Accent private remains package-private. Top-level types, declared constructors, and interface members remain public.
Use this.member / this.method() for declarations and overrides in the current class. Use super.member / super.method() for inherited instance members on the current object or to call a parent implementation. Calls through another object remain normal virtual calls. super bypasses overrides; this retains virtual dispatch. Completion filters this. and super. to follow these rules. Static members declared in the current class require static.member / static.method(). External and inherited static members use the declaring class name. Bare static calls and static access through object references are rejected. Completion after static. offers only static members declared in the current class. Extension blocks keep this as their target receiver.
Migrate old name-based declarations by adding private or protected; rename unprefixed non-public declarations and their references to include _. Change inherited this.member access to super.member. Keep Java library names unchanged; generated storage is exempt from the prefix rule.
Declare at most one ordinary top-level type per .accent file; extension blocks may appear alone or accompany it. See the language guide for the complete rules.
Getting started
- Install JDK 21 and set
JAVA_HOME for builds and VS Code. Follow the Core dependency setup, then build from the AccentEditors root:
./gradlew :tools:accent-language-server:installDist --no-configuration-cache
- Build and install the extension using the instructions below.
- When opening another application's workspace, configure the absolute server launcher path in VS Code settings:
{
"accent.languageServer.path": "/path/to/AccentEditors/tools/accent-language-server/build/install/accent-language-server/bin/accent-language-server"
}
Use the .bat launcher on Windows. When the AccentEditors checkout itself is the workspace, the extension detects this distribution automatically. A configured existing path overrides that detection.
- Reload VS Code and open a
.accent file.
The language server is built separately; the VSIX does not bundle its distribution. Without a server, highlighting and formatting are available, but diagnostics and navigation require the server. accent.trace.server enables LSP tracing (off, messages, or verbose).
Concurrency Syntax
Accent provides two compiler shorthands:
| Shorthand |
Equivalent method call |
Result type |
async expression |
Async.run(() -> expression) |
Async<T> |
await valueAsync |
valueAsync.await() |
T |
The shorthand and method forms have identical behavior. For example:
final customerAsync = async this.customerService.findRequired(id);
final customer = await customerAsync;
Or the equivalent methods:
import accent.runtime.Async;
final customerAsync = Async.run(() -> this.customerService.findRequired(id));
final customer = customerAsync.await();
If findRequired(id) returns Customer, customerAsync has type accent.runtime.Async<Customer>. Both forms can be mixed. The shorthand does not require an import; the explicit method form does. The editor highlights async and prefix await as keywords, while .await() remains a method call.
Building Updated Editor Support
Build accentlang-0.1.4.vsix below for the current syntax, with required non-public prefixes, this/super/static member qualification, ? / ?? contracts, and async / await support. Install it from the repository root:
code --install-extension tools/accent-vscode/accentlang-0.1.4.vsix --force
Reload VS Code after installation. Older local archives retain their previous documentation and are not release artifacts for this repository. Rebuild the language server and install 0.1.4 for diagnostics and completion matching the member, non-null binding, method-result, and collection-element rules.
To rebuild the current package:
From the repository root:
./gradlew :tools:accent-language-server:installDist --no-configuration-cache
cd tools/accent-vscode
npm ci
npm run compile
npm test
npx @vscode/vsce package --out accentlang-0.1.4.vsix
python3 test/package.test.py
Install the newly generated VSIX in VS Code and reload the window. Rebuild the language server as well as the extension so completion, diagnostics, and highlighting use the same language version.
Visible nullability contracts
References and elements are non-null by default. Use String name? for a nullable
binding and name? when referring to it. List<String?> names and
String?[] names allow nullable elements in a non-null collection.
List<String> names?? and String[] names?? permit both a nullable collection
and nullable elements. The former ! and !! contract syntax is obsolete.
A non-null element is accessed as names.get(0) or names[0]. A nullable element
uses names.get(0)? or names[0]?. Optional calls such as names?.get(0)? skip a
null receiver and therefore have a nullable overall result. Declare nullable
method results as String getName?() and call them as customer.getName()?.
Null coalescing uses else: nickname? else "Unknown". It evaluates the fallback
only for null, preserving empty strings, zero, and false. Conditional expressions use
condition then yes else no; ?? is reserved for collection markers.
Non-null fields and locals require initializers. These contracts do not imply
non-empty or immutable values. Rebuild the language server and extension together
for current diagnostics, completion, and highlighting; the VSIX does not bundle
the server. See the language guide
for examples and Java boundary rules.
Mandatory conditional braces
Accent requires { ... } around every if and else body, even one statement.
Use if (user? != null) { names.add(user?); }. else if (...) { ... } chains
remain valid; empty branches use {}. The rule includes for/else fallback
bodies. The language server reports unbraced branches as syntax errors; rebuild
it to get the updated diagnostics. The formatter does not invent missing braces.
For existing code, replace if (ready) return; with
if (ready) { return; }, and else return; with else { return; }.
The unbraced forms are compiler errors, regardless of indentation. This applies
to Accent source; ordinary .java files retain Java's syntax. See the
language guide
for a complete nested if / else if / else example.
Static imports
Use import static java.lang.Math.sqrt; followed by sqrt(value), or import static java.lang.Math.*; for wildcard imports. Imported fields also use bare names, such as PI. No $ prefix is needed. Named imports take precedence over wildcard imports; qualify ambiguous names with their declaring class. Generated Java previews show the resolved class-qualified access.
While loops with else
while (condition) { ... } else { ... } runs else after normal completion, including zero iterations, and skips it when break exits that loop. Both bodies require braces. While expressions can also yield values from the else block.
The expression form is final values = while (condition) { yield value; } else { yield fallback; };. It collects all executed yield values into a list:
- Normal completion can produce
[1, 2, 3]: 1 and 2 from the loop, then 3 from else.
- Zero iterations can produce
[9]: only the fallback from else.
- A
break after yielding 7 produces [7]: the else yields are skipped.
The expression requires a final semicolon. See the while-expression guide.
Do-while loops with else
Use do { ... } while (condition) else { ... }. The single body after do runs at least once. Both bodies require braces. else runs after normal completion and is skipped by a break exiting this loop, a return, or an escaping exception.
The expression form is final values = do { yield value; } while (condition) else { yield fallback; };. It collects body yields followed by else yields on normal completion. A false first condition still produces both the first body value and the fallback; a break skips the fallback. There is no semicolon before else; the complete expression ends with ;.
For-in loops
Migrate each (item from list) to for (item in list) in statements, loop expressions, and HTML markup. The compiler no longer accepts the old syntax. each and from are no longer loop completion or highlighting keywords; in remains usable as an ordinary identifier outside the loop separator position.
Prefer for (item in list) { ... } for collection iteration. The element type is inferred and the binding is implicitly final (it cannot be reassigned or incremented); typed bindings such as for (Customer item in customers) are also supported. Explicit final remains supported but is optional. This fixes the binding; it does not make the referenced object immutable. Bodies require braces.
The expression form is final values = for (item in list) { yield item; } else { yield fallback; };. It collects body yields followed by fallback yields on normal completion. Empty or null collections run else; a break exiting this loop skips it. continue and nested-loop breaks preserve normal outer-loop completion.
Existing enhanced for (var item : list) remains compatible, and traditional counting loops use for (i = 0; i < limit; i++). Completion and highlighting include for and in.
For initializer inference
Traditional loops use for (i = 0; i < limit; i++). An undeclared counter becomes a mutable inferred local; an existing variable is assigned instead. A newly declared counter is scoped to the loop header and body, excluding else. Existing final variables remain protected from reassignment. The same rules apply in loop expressions and with else. Writing var, an explicit type, or final in a traditional Accent for initializer is a syntax error. Ordinary declarations, Java source, and enhanced for (var item : list) remain supported.
Record and model bodies
Write record Address(String city) and model Profile(String name, Address address) without braces when there are no explicit members. Empty or comment-only {} bodies are syntax errors, including for singleton records and models. Nonempty bodies retain braces, and Java records retain Java syntax.
Null fallback uses value? else fallback; ?: is rejected. Inside a conditional's then branch, use parentheses: active then (name? else "Guest") else "Inactive". Only null triggers the fallback.