Skip to content

fix(ext): make tree-sitter highlighting work in Helix 🚁 - #166

Merged
timfennis merged 1 commit into
masterfrom
housekeeping/helix-treesitter-fixes
May 30, 2026
Merged

fix(ext): make tree-sitter highlighting work in Helix 🚁#166
timfennis merged 1 commit into
masterfrom
housekeeping/helix-treesitter-fixes

Conversation

@timfennis

Copy link
Copy Markdown
Owner

Context

Follow-up to #165. Setting up the grammar in Helix surfaced two problems (Neovim was unaffected):

  1. No highlighting in Helix. Helix compiles highlights + injections + locals into one tree-sitter query, so the Neovim-only #lua-match? predicate in injections.scm failed the entire highlight compile (unknown predicate #lua-match?). The LSP still worked, which is why it looked like only highlighting was broken.
  2. Broken Helix setup docs. The README's [[grammar]] git source omitted rev, producing data 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 the tree-sitter highlight CLI (same tree-sitter-highlight crate Helix uses), and that Neovim still loads the query.
  • README Helix section: git sources now include rev (with a local-path alternative), and the build step uses tree-sitter build -o …/grammars/andy-cpp.so instead of hx --grammar build (which rebuilds every grammar and needs the output dir to pre-exist). Added an hx --health check and an hx-vs-helix binary note.

Capture ordering was checked and left as-is: Helix's own bundled queries place the catch-all (identifier) @variable before the specific @function/@variable.parameter captures, confirming Helix resolves overlaps last-match-wins like Neovim, so the existing ordering is correct for both.

🤖

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) <[email protected]>

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

@timfennis
timfennis merged commit 22939e0 into master May 30, 2026
1 check passed
@timfennis
timfennis deleted the housekeeping/helix-treesitter-fixes branch May 30, 2026 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant