Repository navigation
Closed
Description
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:
- Astro (feat: Astro syntax highlighting support #172 / feat: add Astro syntax highlighting support #190) — frontmatter, `<script>`, `<style>`, `{expr}` all inject into TypeScript/CSS. Without injection support, only tags/attributes/comments/brackets get highlighted.
- Svelte — same pattern (`<script>` → TS, `<style>` → CSS).
- HTML — `<script>` / `<style>` contents.
- Markdown — fenced code blocks inject per-language.
- PHP — HTML / embedded segments.
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
- 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.
- 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
- Astro PR that surfaced this: feat: add Astro syntax highlighting support #190
- Issue that triggered it: feat: Astro syntax highlighting support #172
Metadata
Metadata
Assignees
Labels
No labels
Activity
linear commentedon Apr 20, 2026
E-862
feat(syntax): support tree-sitter language injections (unhappychoice#192