Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions .github/workflows/zed.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# The Zed extension (tooling/zed-rx): the extension builds for the target Zed loads, and its queries run on the
# grammar extension.toml pins. A query naming a node that grammar does not have stops Zed loading the language.
# On main, the pin must also be the grammar in the tree; a pull request that changes the grammar only gets a
# warning, since the commit to pin is the one its merge makes.
name: zed

on:
push:
branches: [main]
paths: ["tooling/zed-rx/**", "examples/*.rx", ".github/workflows/zed.yml"]
paths: ["tooling/zed-rx/**", "tooling/tree-sitter-rx/**", "examples/*.rx", ".github/workflows/zed.yml"]
pull_request:
paths: ["tooling/zed-rx/**", "examples/*.rx", ".github/workflows/zed.yml"]
paths: ["tooling/zed-rx/**", "tooling/tree-sitter-rx/**", "examples/*.rx", ".github/workflows/zed.yml"]
workflow_dispatch:

jobs:
Expand All @@ -18,6 +20,8 @@ jobs:
working-directory: tooling/zed-rx
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0 # check-pin.sh compares trees and names the last commit to touch the grammar
- uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-wasip2
Expand All @@ -36,3 +40,21 @@ jobs:
node-version: 22
- name: Queries, on the pinned grammar
run: ./check-queries.sh
- name: Pin is current
env:
EVENT: ${{ github.event_name }}
REF: ${{ github.ref }}
run: |
status=0
./check-pin.sh || status=$?
[ "$status" -eq 0 ] && exit 0
if [ "$status" -ne 1 ]; then
echo "::error::check-pin.sh could not run (exit $status)"
exit 1
fi
if [ "$EVENT" = push ] && [ "$REF" = refs/heads/main ]; then
echo "::error::tooling/tree-sitter-rx differs from the rev tooling/zed-rx/extension.toml pins: bump rev"
exit 1
fi
echo "::warning::tooling/tree-sitter-rx differs from the rev tooling/zed-rx/extension.toml pins." \
"If this changes the grammar, bump rev to the squash commit in a follow-up once it's merged."
12 changes: 10 additions & 2 deletions tooling/zed-rx/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,22 @@ cargo fmt --check
cargo clippy --release --target wasm32-wasip2 -- -D warnings
cargo build --release --target wasm32-wasip2 # rustup target add wasm32-wasip2
./check-queries.sh # needs pnpm
./check-pin.sh
```

`check-queries.sh` runs every query in `languages/reactivescript` over
`examples/*.rx`, on the grammar `extension.toml` pins. A query that names a
node the grammar does not have stops Zed loading the language at all, and Zed
only says so in its log. For a grammar change that is not pinned yet, check
against the working tree: `GRAMMAR=../tree-sitter-rx ./check-queries.sh`. CI
runs all four (`.github/workflows/zed.yml`).
against the working tree: `GRAMMAR=../tree-sitter-rx ./check-queries.sh`.

`check-pin.sh` compares `tooling/tree-sitter-rx` at HEAD (committed changes)
with the tree at `rev`, since Zed only picks up a grammar change once `rev` is
bumped. Exit 1: they differ; exit 2: the check could not run (bad `rev`, fetch
failed). A difference only warns on a pull request, since the commit to pin is
the one the merge makes: bump `rev` to it in a follow-up. On `main` a
difference fails, and so does a check that could not run. CI runs all five,
the pin check last (`.github/workflows/zed.yml`).

Then in Zed:

Expand Down
38 changes: 38 additions & 0 deletions tooling/zed-rx/check-pin.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/sh
# Compares tooling/tree-sitter-rx at extension.toml's rev with HEAD's (committed changes, not the working tree). Zed
# only picks up grammar changes when rev is bumped, so a grammar change merged without the bump never reaches Zed.
#
# Compares the folder's tree at rev, not commits: a squash merge leaves the pinned commit out of main's history, and
# a pin made on a branch is still right when the grammar did not change after it.
#
# Exit status: 0 the trees match; 1 they differ (a rev that predates the folder differs too); 2 the check could not
# run (no rev in extension.toml, rev cannot be fetched or is not a commit, HEAD has no such folder). What a status
# means for CI is the workflow's call (.github/workflows/zed.yml).
set -eu
cd "$(dirname "$0")"

fail() { echo "check-pin: $*" >&2; exit 2; }

pin() { sed -n "/^\[grammars\.rx\]/,\$ s/^$1 = \"\(.*\)\"/\1/p" extension.toml; }
repository=$(pin repository) || fail "cannot read extension.toml"
path=$(pin path) || fail "cannot read extension.toml"
rev=$(pin rev) || fail "cannot read extension.toml"
[ -n "$repository" ] && [ -n "$path" ] && [ -n "$rev" ] ||
fail "extension.toml has no repository, path and rev under [grammars.rx]"

# CI checks out all of history (fetch-depth: 0); a rev outside it is fetched, as check-queries.sh does
git cat-file -e "$rev^{commit}" 2>/dev/null ||
git fetch --quiet --depth 1 "$repository" "$rev" ||
fail "cannot fetch rev $rev from $repository"
git cat-file -e "$rev^{commit}" 2>/dev/null || fail "rev $rev is not a commit"

# rev-parse, not git diff: needs only the two trees, whatever lies between them. No $path at rev counts as differing.
pinned=$(git rev-parse -q --verify "$rev:$path" || echo none)
current=$(git rev-parse "HEAD:$path") || fail "HEAD has no $path"
if [ "$pinned" != "$current" ]; then
last=$(git log -1 --format=%H -- ":(top)$path") || fail "cannot read the history of $path"
echo "$path differs from the pinned rev $rev. The last commit to touch it is $last." >&2
git diff --stat "$rev" HEAD -- ":(top)$path" >&2 || true
exit 1
fi
echo "pin: $rev has $path as HEAD does"
Loading