fix(ext): make tree-sitter highlighting work in Helix 🚁 - #166
Conversation
Helix compiles highlights + injections + locals into a single query, so the Neovim-only `#lua-match?` predicate in injections.scm failed the whole compile and produced no highlighting (the LSP was unaffected). Switch to `#match?`, which both editors support and which reads `^#!` identically. Also fix the README Helix setup: a git grammar source needs `rev` (the cause of the "did not match any variant of GrammarSource" error), and build just this grammar with the tree-sitter CLI instead of `hx --grammar build`. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 577e4ff5ac
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| cd ext/tree-sitter-andy-cpp | ||
| npm install | ||
| mkdir -p ~/.config/helix/runtime/grammars ~/.config/helix/runtime/queries/andy-cpp | ||
| npx tree-sitter build -o ~/.config/helix/runtime/grammars/andy-cpp.so |
There was a problem hiding this comment.
Use Helix’s platform-specific grammar extension
For macOS or Windows users following this Helix setup, hard-coding andy-cpp.so installs the parser under a name Helix will not load. I checked Helix’s loader: it sets DYLIB_EXTENSION to dylib on macOS and dll on Windows, then loads runtime/grammars/<name>.<ext> in get_language (see helix-loader/src/grammar.rs), so hx --health andy-cpp and highlighting will still report no parser off Linux unless the instructions mention the platform-specific extension or use Helix’s build path.
Useful? React with 👍 / 👎.
Context
Follow-up to #165. Setting up the grammar in Helix surfaced two problems (Neovim was unaffected):
highlights+injections+localsinto one tree-sitter query, so the Neovim-only#lua-match?predicate ininjections.scmfailed the entire highlight compile (unknown predicate #lua-match?). The LSP still worked, which is why it looked like only highlighting was broken.[[grammar]]git source omittedrev, producingdata did not match any variant of untagged enum GrammarSource.Changes
injections.scm:#lua-match?→#match?. Both Neovim and Helix support#match?, and^#!matches identically under each editor's regex. Verified the combined query now compiles via thetree-sitter highlightCLI (sametree-sitter-highlightcrate Helix uses), and that Neovim still loads the query.rev(with a local-path alternative), and the build step usestree-sitter build -o …/grammars/andy-cpp.soinstead ofhx --grammar build(which rebuilds every grammar and needs the output dir to pre-exist). Added anhx --healthcheck and anhx-vs-helixbinary note.Capture ordering was checked and left as-is: Helix's own bundled queries place the catch-all
(identifier) @variablebefore the specific@function/@variable.parametercaptures, confirming Helix resolves overlaps last-match-wins like Neovim, so the existing ordering is correct for both.🤖