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
14 changes: 12 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,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
Expand Down
10 changes: 8 additions & 2 deletions tooling/zed-rx/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
29 changes: 29 additions & 0 deletions tooling/zed-rx/check-pin.sh
Original file line number Diff line number Diff line change
@@ -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"
Loading