From ae37a2314c52568f31087bfdad0479cff5c841b7 Mon Sep 17 00:00:00 2001 From: Stefan Kopco Date: Sun, 22 Nov 2026 12:00:12 +0100 Subject: [PATCH 1/2] zed-rx: CI checks the grammar pin, a warning on a pull request and a failure on main --- .github/workflows/zed.yml | 14 ++++++++++++-- tooling/zed-rx/README.md | 10 ++++++++-- tooling/zed-rx/check-pin.sh | 29 +++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 4 deletions(-) create mode 100755 tooling/zed-rx/check-pin.sh diff --git a/.github/workflows/zed.yml b/.github/workflows/zed.yml index cdf5e722..ca198563 100644 --- a/.github/workflows/zed.yml +++ b/.github/workflows/zed.yml @@ -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: @@ -18,6 +20,14 @@ 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 + - name: Pin is current + run: | + ./check-pin.sh || { + [ "${{ github.event_name }}" = pull_request ] && + echo "::warning::the grammar changed: bump rev in tooling/zed-rx/extension.toml once this is merged" + } - uses: dtolnay/rust-toolchain@stable with: targets: wasm32-wasip2 diff --git a/tooling/zed-rx/README.md b/tooling/zed-rx/README.md index 1cf8ebc4..e0b7bc30 100644 --- a/tooling/zed-rx/README.md +++ b/tooling/zed-rx/README.md @@ -33,14 +33,20 @@ 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` fails when `tooling/tree-sitter-rx` differs from what `rev` has, +since Zed only picks up a grammar change once `rev` is bumped; it names the +commit to bump to. On a pull request CI only warns, since the commit to pin is +the one the merge makes; on `main` it fails. CI runs all five +(`.github/workflows/zed.yml`). Then in Zed: diff --git a/tooling/zed-rx/check-pin.sh b/tooling/zed-rx/check-pin.sh new file mode 100755 index 00000000..199f8192 --- /dev/null +++ b/tooling/zed-rx/check-pin.sh @@ -0,0 +1,29 @@ +#!/bin/sh +# Fails when tooling/tree-sitter-rx is not what extension.toml's rev has. 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 with HEAD's, 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. +set -eu +cd "$(dirname "$0")" + +pin() { sed -n "/^\[grammars\.rx\]/,\$ s/^$1 = \"\(.*\)\"/\1/p" extension.toml; } +repository=$(pin repository) +path=$(pin path) +rev=$(pin rev) + +# 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" + +# rev-parse, not git diff: needs only the two trees, whatever lies between them +pinned=$(git rev-parse -q --verify "$rev:$path" || echo none) +current=$(git rev-parse "HEAD:$path") +if [ "$pinned" != "$current" ]; then + last=$(git log -1 --format=%H -- ":(top)$path") + echo "$path changed since the rev extension.toml pins ($rev)." >&2 + echo "Set [grammars.rx] rev to $last (the last commit to touch it) and commit that." >&2 + echo "Changed:" >&2 + git diff --stat "$rev" HEAD -- ":(top)$path" >&2 + exit 1 +fi +echo "pin: $rev has $path as HEAD does" From d222d29851a3274a22e5e0fefb7c7100c3531d2d Mon Sep 17 00:00:00 2001 From: Stefan Kopco Date: Sun, 22 Nov 2026 13:14:32 +0100 Subject: [PATCH 2/2] zed-rx: pin check last, a broken rev fails everywhere, messages that state facts --- .github/workflows/zed.yml | 24 +++++++++++++++++------ tooling/zed-rx/README.md | 12 +++++++----- tooling/zed-rx/check-pin.sh | 39 +++++++++++++++++++++++-------------- 3 files changed, 49 insertions(+), 26 deletions(-) diff --git a/.github/workflows/zed.yml b/.github/workflows/zed.yml index ca198563..c62b7f80 100644 --- a/.github/workflows/zed.yml +++ b/.github/workflows/zed.yml @@ -22,12 +22,6 @@ jobs: - uses: actions/checkout@v5 with: fetch-depth: 0 # check-pin.sh compares trees and names the last commit to touch the grammar - - name: Pin is current - run: | - ./check-pin.sh || { - [ "${{ github.event_name }}" = pull_request ] && - echo "::warning::the grammar changed: bump rev in tooling/zed-rx/extension.toml once this is merged" - } - uses: dtolnay/rust-toolchain@stable with: targets: wasm32-wasip2 @@ -46,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." diff --git a/tooling/zed-rx/README.md b/tooling/zed-rx/README.md index e0b7bc30..90a03abc 100644 --- a/tooling/zed-rx/README.md +++ b/tooling/zed-rx/README.md @@ -42,11 +42,13 @@ 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`. -`check-pin.sh` fails when `tooling/tree-sitter-rx` differs from what `rev` has, -since Zed only picks up a grammar change once `rev` is bumped; it names the -commit to bump to. On a pull request CI only warns, since the commit to pin is -the one the merge makes; on `main` it fails. CI runs all five -(`.github/workflows/zed.yml`). +`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: diff --git a/tooling/zed-rx/check-pin.sh b/tooling/zed-rx/check-pin.sh index 199f8192..99395310 100755 --- a/tooling/zed-rx/check-pin.sh +++ b/tooling/zed-rx/check-pin.sh @@ -1,29 +1,38 @@ #!/bin/sh -# Fails when tooling/tree-sitter-rx is not what extension.toml's rev has. Zed only picks up grammar changes when -# rev is bumped, so a grammar change merged without the bump never reaches Zed. +# 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 with HEAD's, 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. +# 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) -path=$(pin path) -rev=$(pin rev) +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" +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 +# 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") +current=$(git rev-parse "HEAD:$path") || fail "HEAD has no $path" if [ "$pinned" != "$current" ]; then - last=$(git log -1 --format=%H -- ":(top)$path") - echo "$path changed since the rev extension.toml pins ($rev)." >&2 - echo "Set [grammars.rx] rev to $last (the last commit to touch it) and commit that." >&2 - echo "Changed:" >&2 - git diff --stat "$rev" HEAD -- ":(top)$path" >&2 + 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"