Skip to content

feat(syntax): support tree-sitter language injections #191

Closed

Description

@unhappychoice

Background

Gitlogue's syntax highlighter in `src/syntax/mod.rs` uses a single `tree_sitter::Query` against a single parse tree. It does not process tree-sitter language injections (`(#set! injection.language "...")` captures).

Several grammars we support rely heavily on injections for the "interesting" parts of a file:

As a result, a lot of real code in these files is rendered unhighlighted.

Goal

Teach the highlighter to resolve `injections.scm` captures, parse the injected regions with the injected language's parser, and merge the resulting highlight spans into the output.

Possible approaches

  1. Adopt the `tree-sitter-highlight` crate — has built-in injection handling but requires mapping its `Highlight` indices back to our `TokenType` enum and ship highlight name tables per language.
  2. Hand-rolled injection resolution — walk the tree, run `injections.scm` as a separate query, recursively highlight the matched ranges with the target language, then merge spans. Keeps our existing `TokenType` mapping logic.

Approach 2 is probably a smaller change and keeps theming consistent, but needs care around:

  • `(#set! injection.combined)` (merge siblings into one parse)
  • Loading `injections.scm` alongside `highlights.scm` per language (currently only `HIGHLIGHT_QUERY` is exposed per module)
  • Recursion depth / cycles
  • Extending `get_language()` so injected language names (e.g. `"typescript"`, `"css"`) resolve to a `(Language, &str)` pair

Out of scope

  • Injection targets we don't bundle as dependencies (e.g. bash-in-markdown when we don't have a bash grammar loaded). Fall back to plain text.

References

Activity

  1. linear commented on Apr 20, 2026

    @linear
  2. added a commit that references this issue on Apr 20, 2026
    e76953e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions