Skip to content

fix(ide): restore tree-sitter query sync - #178

Open
samim-reza wants to merge 1 commit into
ziex-dev:mainfrom
samim-reza:fix/136-sync-tree-sitter-queries
Open

fix(ide): restore tree-sitter query sync#178
samim-reza wants to merge 1 commit into
ziex-dev:mainfrom
samim-reza:fix/136-sync-tree-sitter-queries

Conversation

@samim-reza

Copy link
Copy Markdown

Summary

tools/syncqueries — the script that copies pkg/tree-sitter-zx/queries/ out to the Zed and Neovim query directories and to the docs site — had drifted from the tree. Running it today would have deleted SQL highlighting from the Zed and Neovim extensions, and its docs-site destination pointed at a directory that no longer exists.

This makes the canonical pkg/ queries the real source of truth again. After this change bash tools/syncqueries is a no-op on a clean tree.

Problem

1. SQL injections only ever existed in the editor copies.

ide/zed/languages/zx/injections.scm gained SQL injection patterns for db.query(...) / zx.db.run(...) (most recently in e7d30cf fix(ide): improve SQL injection pattern), and the Neovim copy carries an older variant of them. The canonical pkg/tree-sitter-zx/queries/injections.scm was never updated and still only has the comment injection:

$ git log --oneline -- pkg/tree-sitter-zx/queries/injections.scm
5dcbb21d refactor: renamed packages -> pkg

$ git log --oneline -- ide/zed/languages/zx/injections.scm
e7d30cf5 fix(ide): improve SQL injection pattern
406e6749 perf: incrementality for compilation and devserver reload
89793f28 refactor: rn editors -> ide

Two consequences:

  • tools/syncqueries does rm -f then cp per file, so running it would have overwritten both editor copies with the pattern-less canonical version, silently dropping SQL highlighting.
  • Consumers that read queries straight from the grammar package — nvim-treesitter's install_info, hx --grammar fetch, the npm queries/* files listed in pkg/tree-sitter-zx/package.json — never had the SQL injections at all.

2. The docs-site destination was stale.

SITE_PAGES_DIR still pointed at site/pages/docs. That path was moved to site/app/pages/reference in 4d9dc45 refactor: make docsite it's own module, and site/app/pages/reference/util.zig is what actually does @embedFile("./highlights.scm"). Because the script mkdir -ps its destinations, running it created an empty site/pages/docs/ and left the file the site really embeds untouched.

Root Cause

Edits went into the generated copies instead of the source, and a directory rename was not reflected in the tool. Nothing verifies that the copies match, so both went unnoticed.

Solution

  • Promote the Zed version of the SQL injection patterns (the newest) into pkg/tree-sitter-zx/queries/injections.scm.
  • Point SITE_PAGES_DIR at site/app/pages/reference.
  • Re-run tools/syncqueries, which brings ide/neovim/queries/zx/injections.scm up to the improved patterns. Zed and the site copy are already byte-identical to the new source, so they are untouched.

No behaviour is removed anywhere — Neovim gains the newer patterns, and the grammar package plus its downstream consumers gain the SQL injections for the first time.

Testing

  • bash tools/syncqueries then git status — the only file it rewrites is the stale Neovim injections.scm; a second run leaves the tree clean, so the tool is now idempotent and no stray site/pages/ directory is created.

  • The new canonical injections.scm was checked against the real grammar (pkg/tree-sitter-zx/src/parser.c, ABI 15) with a small ts_query_new + ts_query_cursor harness built on the vendored tree-sitter runtime:

    before: query ok: 1 patterns, 1 captures  → injection.content 0
    after:  query ok: 3 patterns, 4 captures  → injection.content 2
    

    on a sample containing db.query("SELECT ..."), zx.db.run("DELETE ...") and a multiline-string query — so the patterns compile and actually match.

  • zig build and zig build test with Zig 0.17.0-dev.1465+8b2d0ce21 (the version pinned in CI): 591 pass, 0 fail, 11 skipped, unchanged from main.

Related Issue

Related to #136 (feat: ide support) — keeps the Zed/Neovim integrations tracked there in sync with the grammar package.

`tools/syncqueries` copies `pkg/tree-sitter-zx/queries/` to the Zed and
Neovim query directories and to the docs site, but it had drifted from
the tree in two ways:

- The SQL injection patterns were only ever added to
  `ide/zed/languages/zx/injections.scm` (and an older variant to the
  Neovim copy), never to the canonical `pkg/` source. Running the tool
  would have deleted SQL highlighting from Zed and Neovim, and consumers
  that read queries straight from the grammar package - nvim-treesitter,
  `hx --grammar fetch` - never had them at all.

- The docs-site destination still pointed at `site/pages/docs`, which
  moved to `site/app/pages/reference`. The tool created an empty
  `site/pages/docs/` and left the file the site actually embeds
  untouched.

Promote the Zed version of the injections to the canonical source, point
the site destination at the current path, and re-run the tool so every
copy matches. `tools/syncqueries` is now a no-op on a clean tree.
Copilot AI lite review requested due to automatic review settings August 22, 2026 22:40
@github-project-automation github-project-automation Bot moved this to Todo in Ziex Aug 22, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Restores pkg/tree-sitter-zx/queries/ as the canonical source of truth for tree-sitter queries by aligning injection patterns across consumers and fixing the docs-site copy destination in tools/syncqueries.

Changes:

  • Update tools/syncqueries to copy highlights.scm to the new docs-site directory (site/app/pages/reference).
  • Promote SQL injection query patterns into the canonical pkg/tree-sitter-zx/queries/injections.scm.
  • Sync Neovim’s ide/neovim/queries/zx/injections.scm to the updated canonical injection patterns.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
tools/syncqueries Fix docs-site destination path for highlights.scm sync.
pkg/tree-sitter-zx/queries/injections.scm Add canonical SQL injection patterns for db.* and zx.db.*.
ide/neovim/queries/zx/injections.scm Update Neovim injections to match the canonical SQL injection patterns.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread tools/syncqueries
Comment on lines +45 to 49
# Copy highlights.scm to the docs site
echo "Copying highlights.scm to the docs site..."
rm -f "$SITE_PAGES_DIR/highlights.scm"
cp "$SOURCE_DIR/highlights.scm" "$SITE_PAGES_DIR/highlights.scm"
echo " Copied: highlights.scm"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

2 participants