Skip to content

zed-rx: a Zed extension for .rx - #2

Closed
oddcelot wants to merge 11 commits into
mainfrom
zed-rx
Closed

oddcelot wants to merge 11 commits into
mainfrom
zed-rx

Conversation

@oddcelot

@oddcelot oddcelot commented Nov 18, 2026 •

Copy link
Copy Markdown
Owner

Hi! This adds a Zed extension for .rx and .d.rx in tooling/zed-rx. It builds on the tree-sitter grammar from solidjs#88 and fills the gap the language server README mentions: "Zed needs an extension of its own; there isn't one yet".

The extension starts the same language server VS Code runs, so hover, go to definition, references, rename, completion, type errors and the compiler's diagnostics behave the same. It installs @reactivescript/language-server from npm and updates it when there's a newer release. If it's offline or the update fails, it keeps the copy it already has. The compiler comes inside that package as WebAssembly, so there's nothing to build per platform.

On the tree-sitter side there are queries for:

  • highlighting, where sources, equations and writes each get their own capture (table below)
  • the outline: components, fns, actions, sources, equations, contexts, errors and types
  • indentation, brackets, JSX tag auto-close and Vim text objects
  • injections: <style> as CSS, /** */ as JSDoc, regex literals, and css, html, sql, graphql/gql and styled templates. rx fences in Markdown are highlighted too.

Trying it

Run zed: install dev extension and pick tooling/zed-rx. Zed builds it with Rust from rustup.

Note

Like the VS Code extension, the server expects a tsconfig.json with "jsx": "preserve" and "jsxImportSource": "@solidjs/web", and @solidjs/web in node_modules.

Highlighting

Code in examples/todo.rx Capture Reads as
source todos, nextId := nextId + 1 @variable.special state
shown = …, remaining = … @constant derived
:= @keyword.operator a write

Markup inside exported components and control blocks is highlighted too, which is what solidjs#86 fixed for the TextMate grammar.

examples/todo.rx in Zed with the outline panel open and a hover showing (parameter) ts: Todo[] Zed's language server menu with rx-language-server running

Settings

All optional, under lsp.rx-language-server in Zed's settings.json. They're the same three settings the VS Code extension has.

Setting What it does Default
binary Runs another server, such as one from a checkout. Zed starts it without the extension, see below The npm package
settings.rxc.path Uses an rxc binary instead of the WebAssembly build The bundled build
settings.typescript.tsdk TypeScript's lib folder The project's node_modules/typescript/lib, else the server's own
Example
{
  "lsp": {
    "rx-language-server": {
      "settings": {
        "rxc": { "path": "/path/to/reactivescript/compiler/target/release/rxc" },
        "typescript": { "tsdk": "/path/to/project/node_modules/typescript/lib" }
      }
    }
  }
}

With binary.path set, Zed runs that command itself and never asks the extension. It doesn't add --stdio, doesn't run a .js file with its Node, and doesn't read settings.rxc.path, so all three have to go in binary:

A server from a checkout
{
  "lsp": {
    "rx-language-server": {
      "binary": {
        "path": "node",
        "arguments": ["/path/to/reactivescript/tooling/rx-language-server/bin/server.js", "--stdio"],
        "env": { "RXC": "/path/to/reactivescript/compiler/target/release/rxc" }
      }
    }
  }
}

Zed has semantic tokens off by default. "languages": { "ReactiveScript": { "semantic_tokens": "combined" } } turns the server's on.

Notes for review

The queries are MIT. I wrote them from the grammar's own queries and from tree-sitter-javascript's and tree-sitter-typescript's. Zed's built-in TSX queries are GPL, so none of their text is in here.

rev in extension.toml pins the grammar at b470614, the squash commit of solidjs#88. A grammar change only reaches Zed once that line is bumped.

injections.scm has one pattern per template tag with the language written out, the way Zed's TSX injections do it. Taking the language from the tag's capture with injection.combined would be shorter, but it broke JSX tag auto-close everywhere in a .rx file.

TypeScript is only looked up at the worktree root. A project that hoists node_modules to a parent folder has to set settings.typescript.tsdk.

The server README also loses "Neovim has no .rx grammar yet", which stopped being true with solidjs#88.

Testing

  • cargo build --release --target wasm32-wasip2, cargo clippy and cargo fmt --check pass
  • ./check-queries.sh runs all seven query files through tree-sitter query on the examples, on the grammar extension.toml pins
  • The new zed workflow runs the cargo checks and check-queries.sh in CI
  • The published npm package (0.3.1) has bin/server.js where the extension starts it
  • Installed as a dev extension and checked by hand on examples/shop and examples/todos.rx

Not included

  • Snippets, and tasks for rx-tsc
  • Theme rules for the server's source and equation semantic tokens
  • Looking for TypeScript in parent folders
  • Publishing to Zed's extension registry, which needs a PR to zed-industries/extensions. Until then it's a dev extension.

Every comment was handed to the JSDoc grammar, so a // line came out as
JSDoc description text, and its words lost the comment colour up to the
first comma or full stop.
…th as Zed runs it

Zed starts lsp.rx-language-server.binary.path itself and never asks the
extension for a command, so the branch that read it was dead: no --stdio,
no Node for a .js file, no RXC. The README now shows the settings that work.

A failed npm install no longer stops a server that is already on disk, and
an install whose bin/server.js is missing is installed again.
…ns, ' closes

The type_arguments and type_parameters patterns sat before the operator
list, which also has < and >, and the later pattern wins.
With the language taken from the tag's capture and injection.combined,
Zed's JSX tag auto-close did nothing anywhere in a .rx file, even where
no template matched. One pattern per tag, the language named, as in
Zed's own TSX injections, brings it back; css`…` still highlights.
…*/ is not a doc comment

Object and array patterns of a parameter are parameters, on optional
parameters too. The root of a write or guess was found three members deep;
a query cannot recurse, so it is four now and the cap is written down.
/**/ and a /*** banner were doc comments in highlights.scm but not JSDoc in
injections.scm; both use the same test now.
…he pinned grammar

No workflow built tooling/zed-rx or ran its queries. A query that names a
node the grammar does not have stops Zed loading the language, so
check-queries.sh runs every query over examples/*.rx on the grammar
extension.toml pins, fetched from the repository named there when the
checkout does not have it. zed.yml runs it after fmt, clippy and the
wasm32-wasip2 build.

The README says how to run the same checks and where to look in Zed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant