Hew Language Support for VS Code
Syntax highlighting and language support for the Hew programming language.
Features
- Full syntax highlighting for Hew language constructs
- Language Server Protocol — completion, hover, definition, document symbols, semantic tokens, diagnostics (language server included in the published extension)
- Document formatting — format on save via
hew fmt (requires hew CLI)
- Actor declarations —
actor, receive fn, receive, init
- Supervisor trees —
supervisor, child, strategy, intensity, within
- Structured concurrency —
scope, fork, await, select
- Generators —
gen fn, yield
- Wire types —
#[wire] attribute on type/enum declarations, field tags with @
- Traits and generics —
trait, impl ... for, type parameters <T: Send>, generic closures |<T: Eq> left: T, right: T| -> bool { left == right }
- Pattern matching —
match, =>, guards, destructuring
- Post-cutover paths — dotted paths (
std.time), import selections (std.time.{Instant}), and contextual variants (.Ready)
- All built-in types —
i8–i64, u8–u64, f32, f64, bool, char, string
- String variants — regular
"...", raw r"...", byte b"...", interpolated f"...{expr}...", char 'x'
- Duration literals —
100ms, 5s, 1h
- Comments —
//, /* */, /// (doc comments)
- Auto-closing pairs for brackets, braces, parentheses, strings
- Code folding and bracket matching
Example
actor Counter {
var count: i32 = 0;
receive fn increment() {
self.count = self.count + 1;
}
receive fn get() -> i32 {
self.count
}
}
supervisor CounterSupervisor {
strategy: one_for_one;
intensity: 5 within 30s;
child counter: Counter;
}
fn fibonacci(n: i32) -> i32 {
if n <= 1 {
n
} else {
fibonacci(n - 1) + fibonacci(n - 2)
}
}
fn main() -> i32 {
let result = fibonacci(10);
println(result);
0
}
Path syntax
Hew paths use dots: import std.time and clock.now(). Select several names
from a module with import std.time.{Instant, Duration}, and use .Variant
for a contextual enum variant in a match. The retired :: separator reports
E_PATH_LEGACY_SEPARATOR, glob imports report E_IMPORT_GLOB_REMOVED, and
turbofish syntax reports E_LEGACY_TURBOFISH.
Installation
From the Marketplace
Install Hew Language
in VS Code, then open a .hew file. Platform packages include a matched Hew
SDK for language features, formatting and debug builds. The extension starts
its language server with hew lsp and uses the same SDK for its other tools.
You can select an installed SDK with hew.lsp.serverPath; point it at bin/hew
(or bin/hew.exe on Windows).
From VSIX (local install)
- In the extension directory, stage the SDK for your platform
and package it:
scripts/stage-hew-sdk.sh linux-x64 # or linux-arm64, darwin-arm64, win32-x64
npx vsce package --target linux-x64
- In VS Code, open the command palette (
Ctrl+Shift+P) and run:
Extensions: Install from VSIX...
- Select the generated
.vsix file
From source (development)
- Clone this repository
- Run
npm install && npm run build:dev
- Open this folder in VS Code and press
F5 to launch the Extension Development Host
Validate the controlled Hew fixtures with a compiler explicitly selected for the
check:
HEW_COMPILER=/path/to/hew npm run test:fixtures
Releasing
Push a vX.Y.Z tag matching package.json; .github/workflows/release.yml
packages every platform with the Hew SDK pinned in
hew-release.sha256 and publishes after approval. See
docs/publishing.md.
Configuration
| Setting |
Default |
Description |
hew.lsp.serverPath |
"" |
Path to hew for hew lsp. If empty, searches trusted workspace target/, PATH, and the bundled SDK. |
hew.formatterPath |
"" |
Path to hew for formatting. If empty, uses hew.lsp.serverPath or the same trusted SDK search. |
hew.debugger.hewPath |
"" |
Path to the hew compiler used for debug builds. If empty, uses hew.lsp.serverPath or the same trusted SDK search. |
hew.allowUntrustedWorkspaceBinaries |
false |
Allows auto-detecting workspace target/release and target/debug binaries even in Restricted Mode. Set this in user settings only when you explicitly trust those workspace binaries. |
Workspace-built hew binaries are only auto-selected in trusted workspaces by default. In Restricted Mode, trust the workspace or set hew.allowUntrustedWorkspaceBinaries in user settings to opt in.
Debugging
Before launching a Hew debug session:
- If
program points to a .hew source file, make sure hew.debugger.hewPath is set or hew is on PATH so the extension can run hew build --debug.
- Make sure the selected backend executable is on
PATH:
debuggerBackend: "auto" picks lldb-mi on macOS and gdb elsewhere.
debuggerBackend: "lldb" requires lldb-mi.
debuggerBackend: "gdb" requires gdb.
Example .vscode/launch.json:
{
"version": "0.2.0",
"configurations": [
{
"type": "hew",
"request": "launch",
"name": "Debug Hew Program",
"program": "${workspaceFolder}/main.hew",
"debuggerBackend": "auto"
}
]
}
If preflight reports that a backend is unavailable, either install the required tool or switch debuggerBackend to a backend that is already installed on your system.
Supported Token Scopes
| Hew Construct |
TextMate Scope |
fn, let, var, const, type, enum, trait, impl, gen |
keyword.declaration |
if, else, match, loop, for, while, return, await, scope |
keyword.control |
actor, receive, spawn, init, fork, this |
keyword.actor |
supervisor, child, restart, budget, strategy |
keyword.supervisor |
machine, state, event, on, when, entry, exit, emit |
keyword.control.machine |
reserved, optional, deprecated, default |
keyword.wire |
dyn, is, unsafe |
keyword.other |
&&, \|\| |
keyword.operator.logical |
dotted paths, .{...} import selections, .Variant |
punctuation.accessor, meta.import.selection, entity.name.variant |
one_for_one, pool, brutal_kill, permanent, true, false |
constant.language |
events, emits, reenter, initial, mailbox, overflow, intensity, within, shutdown, infinity, wired_to, export, resource, linear, opaque, wire, json, yaml, repeated, coalesce, fallback, drop_new, drop_old, block, fail |
variable.language.contextual |
i32, u64, f64, bool, string |
storage.type |
Result, Option, Send, Frozen, HashSet, LocalPid, RemotePid, LambdaPid |
storage.type |
| PascalCase identifiers |
entity.name.type |
| Function names in definitions |
entity.name.function |
| Function calls |
entity.name.function.call |
self |
variable.language.self |
"string", r"raw", b"bytes", f"interpolated {x}", 'c' |
string.quoted |
42, 0xFF, 0b1010, 3.14, 100ms |
constant.numeric |
//, /* */, /// |
comment |
License
Licensed under the Apache License, Version 2.0. See LICENSE for details.
Updating syntax highlighting
Edit structural TextMate rules in syntaxes/hew.tmLanguage.json. Keyword and
built-in type lists come from the compiler's docs/syntax-data.json; regenerate
them with the shared compiler tool from this repository's root:
HEW_VSCODE_HEW="$PWD" node ../hew/tools/downstream/generate-tmgrammar.mjs
cp ../hew/dist/hew.tmLanguage.json syntaxes/hew.tmLanguage.json
npm test
Consuming receivers use consume self. Generators use gen fn, and stream
iteration uses plain for. The retired async gen fn, for await and infix
| after forms are highlighted as errors.
Macro expansion views
With a compiler that supports expansion metadata, use Hew: Expand Macro at
Cursor for the selected invocation or Hew: Show Expanded Document for the
whole source file. The read-only Hew view opens beside your source and refreshes
after source analysis. Hew: Refresh Expansion requests another view, and
Hew: Go to Expansion Source opens the original document, an invocation or
its selected rule.
Expansion views are for inspection. Context comments distinguish hygienic names
but do not make the rendered text a standalone equivalent program. Diagnostics
and test execution use the original Hew source. Test imported macros in ordinary
#[test] functions and run them through the existing Testing panel.
Experimental live source
With the live-execution SDK installed, run Hew: Attach Live Node and enter
the node endpoint and its authenticated NodeId. The SDK uses the existing
HEW_NODE_CONFIG for your local identity and grants. Its documented SDK paths
can be supplied through HEW_LIVE_NODE_MODULE, HEW_LIVE_RUNTIME,
HEW_LIVE_COMPILER, HEW_WASI_SDK and HEW_LIVE_WASM_LIB_DIR when running
from a development SDK. Set hew.live.executable if the companion is not on
PATH; hew.live.endpoint and hew.live.node supply connection defaults.
When an ordinary Hew file is open, attachment obtains the SDK's generated
service context and starts its selected compiler as the language server.
Diagnostics and service completions use the same virtual module as component
builds. Definitions open the exact SDK source in a read-only document; no
generated files are added to the project. Dirty editor buffers take precedence.
Disconnecting removes the analysis context and clears its generated views.
An older bundled language server cannot provide this experimental context;
use a matching live SDK rather than a stable compiler fallback.
Open a saved .hew component and run Hew: Prepare Live Source. Subsequent
saves prepare it again through the ordinary compiler, including its imports.
An edit invalidates the previous preparation. Compilation errors appear in
Hew Live output and leave the running version in place.
Run Hew: Activate Prepared Source when ready. The SDK checks the observed
predecessor epoch and applies the replacement with a five-second drain budget.
The status bar shows the active epoch and whether a new component is prepared.
Hew: Show Live Status requests the current node status. If the connection
is lost during activation, reconnect and check that status before continuing;
the extension never automatically retries an activation. Use Hew: Disconnect
Live Node to close the local companion.
| |