Skip to content

feat(editor): syntax highlighting for Glimmer .gjs/.gts files - #13236

Merged
nwparker merged 1 commit into
stablyai:mainfrom
albarracin-jorge:feat/glimmer-handlebars-highlighting
Oct 28, 2026
Merged

nwparker merged 1 commit into
stablyai:mainfrom
albarracin-jorge:feat/glimmer-handlebars-highlighting

Conversation

@albarracin-jorge

@albarracin-jorge albarracin-jorge commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

Ember developers write .gjs and .gts files. These mix normal JavaScript/TypeScript with small HTML-like <template> blocks. Orca used to show these files as plain, uncolored text. Now it colors the code part like JavaScript/TypeScript and the template part like Handlebars, so these files are as easy to read as any other code file.

What Changed

Before: opening a .gjs or .gts file in the editor or diff viewer showed it as plaintext, with no highlighting.
After: .gts gets TypeScript colors and .gjs gets JavaScript colors. Each <template>...</template> block is colored as Handlebars, including HTML tags, attributes and {{ }} mustaches. This works for inline templates too, and so does a component that is only a template.

How it works:

  • src/shared/editor-language/editor-language-detect.ts maps .gjs to glimmer-js and .gts to glimmer-ts. The lookup ignores case and path separators.
  • New src/renderer/src/lib/monaco-languages/register-glimmer.ts adds one Monarch grammar, generated in a JS variant and a TS variant:
    • The script is the background embed, and each <template> is a handlebars island.
    • Every exit from a template goes back through a zero-width @rematch in root, which pushes the script embed again. That way @pop never runs when no embed is active.
    • Embed entry is limited by the shared restOfLineWithinEmbedBudget. Lines over the budget keep the template boundaries but skip embeds, so a line packed with hundreds of template islands cannot overflow Monarch's recursion. This is the same invariant the Astro/Svelte/Vue grammars follow.
    • Both languages are registered in monaco-setup.ts next to Vue/Svelte/Astro.
  • Mobile parity: mobile/src/session/mobile-file-syntax.ts maps glimmer-js and glimmer-ts to lowlight's javascript and typescript, so mobile gets approximate JS/TS highlighting instead of plaintext.
  • .hbs and .handlebars already map to Monaco's built-in handlebars on main (fix(editor): recognize all bundled Monaco language associations #23371). The original PR's change for those is not included here.

Why

Ember's template-tag format is the default for new Ember and Glimmer code, and Monaco has no Glimmer language built in. A Monarch embed grammar is the same approach as the existing Vue/Svelte/Astro support. It reuses Monaco's built-in TS/JS and Handlebars tokenizers instead of writing a new lexer.

Known limitation, the same one Vue/Svelte/Astro have: a literal <template> inside a JS string or comment switches the coloring to Handlebars until the next </template>.

Linked Issue

N/A. There is no linked issue; this was a community feature PR.

Visual Proof

The same hello.gts file, opened in a non-git folder workspace:

Before (main) After (this PR)
before gts after gts
before gjs after gjs

Testing

  • Reproduced on main: detectLanguage('…/hello.gjs') returns plaintext, and the new detection test fails with expected 'plaintext' to be 'glimmer-js'.

  • Tokenizer tests drive the real MonarchTokenizer through monarch-tokenizer-test-harness. They use inline snapshots to show which language covers each line, and they include a template-only component, inline templates, and an empty template.

  • monarch-embed-entry-recursion.test.ts has a new Glimmer block:

    • Nesting depth stays within the embed budget on a ramp of up to 900 islands per line. Without the budget, depth reached 1800.
    • The script and template embeds come back after lines that go over the budget.
  • Electron, launched in the background with CDP screenshots, macOS, non-git folder workspace:

    • hello.gts and hello.gjs showed TS/JS colors, with Handlebars inside templates.
    • The console showed no Monarch embed errors.
    • With main's detection swapped in, both files showed as plaintext.
  • pnpm test on the touched test files (147 tests) passed. oxfmt --check, oxlint (anti-slop and code-quality configs), ast-grep and check-changed-code-quality were all clean.

  • Cross-platform: this is a renderer-only change. Extension detection ignores case and path separators, and a Windows path is covered by a test.

  • Remote/mixed versions: there is no protocol change. An older client or mobile that gets an unknown glimmer-* id falls back to plaintext, which is what happens today.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

Review

Two rounds of adversarial review. Fixes made during review:

  • The embed-entry budget had been missing. Without it, a long line of template islands made Monarch recurse very deeply.
  • Removed type assertions from the tests.

Accepted trade-off: a literal <template> inside a string or comment switches the coloring (see Why).

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Original fix by @albarracin-jorge in #13236. Their authorship is kept on the commit.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@coderabbitai

coderabbitai Bot commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Added detection for .gjs, .gts, .hbs, and .handlebars files. Added Monaco language definitions for Glimmer JavaScript and TypeScript. The tokenizer embeds the corresponding script language and Handlebars within <template> regions. Added shared editor configuration and idempotent registration. Monaco setup now registers both Glimmer languages. Tests cover path handling, tokenization transitions, language metadata, and repeated registration.

Pre-merge checks: Passed 3 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Description check Warning The description is detailed and covers the change, rationale, testing, visual proof, limitations, and checklist. However, it lists “N/A” for Linked Issue even though the repository template requires a… Add a valid linked issue under the Linked Issue section. If this is a maintainer contribution, confirm the contributor status and apply the repository’s maintainer exception instead.
Passed Passed checks: 3 passed
Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Title check Passed The title clearly identifies the primary change: Glimmer syntax highlighting for .gjs and .gts files.
Full details: Description check

Explanation

The description is detailed and covers the change, rationale, testing, visual proof, limitations, and checklist. However, it lists “N/A” for Linked Issue even though the repository template requires an actual linked issue for community contributions.

Resolution

Add a valid linked issue under the Linked Issue section. If this is a maintainer contribution, confirm the contributor status and apply the repository’s maintainer exception instead.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/renderer/src/lib/monaco-languages/register-glimmer.ts (1)

6-50: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Reduce explanatory comments in the Glimmer tokenizer and its tests.

Keep only comments that state non-obvious invariants or fixture rationale.

  • src/renderer/src/lib/monaco-languages/register-glimmer.ts#L6-L50: retain a short embed-stack invariant comment and remove state-transition walkthroughs.
  • src/renderer/src/lib/monaco-languages/register-glimmer.test.ts#L65-L84: remove comments that restate fixture contents and assertions.

As per coding guidelines, comments must be concise, limited to non-obvious information, and must not describe how code works.

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 85067b4a-5d97-4003-8edc-0361e8274472

📥 Commits

Reviewing files that changed from the base of the PR and between 6da7b8e and a732910877419a5117ddff5d80c8816f513de5b6.

📒 Files selected for processing (5)
  • src/renderer/src/lib/language-detect.test.ts
  • src/renderer/src/lib/language-detect.ts
  • src/renderer/src/lib/monaco-languages/register-glimmer.test.ts
  • src/renderer/src/lib/monaco-languages/register-glimmer.ts
  • src/renderer/src/lib/monaco-setup.ts

@albarracin-jorge albarracin-jorge changed the title feat: Glimmer & Handlebars syntax highlighting (.gjs/.gts/.hbs) feat(editor): syntax highlighting for Glimmer and Handlebars Aug 8, 2026
@albarracin-jorge
albarracin-jorge force-pushed the feat/glimmer-handlebars-highlighting branch from a732910 to d8d94bf Compare August 8, 2026 17:44

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a3324983-d9ef-42ca-ad7e-ce5ac3a3b9e1

📥 Commits

Reviewing files that changed from the base of the PR and between a732910877419a5117ddff5d80c8816f513de5b6 and d8d94bf.

📒 Files selected for processing (2)
  • src/renderer/src/lib/monaco-languages/register-glimmer.test.ts
  • src/renderer/src/lib/monaco-languages/register-glimmer.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/renderer/src/lib/monaco-languages/register-glimmer.ts

@nwparker

Copy link
Copy Markdown
Contributor

Thanks @albarracin-jorge for this work. #23371 covers the .hbs / .handlebars filename mappings through Monaco's built-in metadata; I verified both resolve to handlebars and credited this contribution in that PR.

Keeping this PR open because its Glimmer .gjs / .gts grammars are additional functionality that #23371 does not implement. Those mappings and tokenizers are still needed.

Register glimmer-js and glimmer-ts Monaco languages that embed
JavaScript/TypeScript as the background script and tokenize each
<template> block as a Handlebars island. Embed entry is bounded by the
shared line budget so long lines cannot blow the Monarch recursion
limit. Mobile maps the new ids to javascript/typescript highlighting.

Co-authored-by: Neil <[email protected]>
@nwparker
nwparker force-pushed the feat/glimmer-handlebars-highlighting branch from f1fe66d to 0a4ef06 Compare October 28, 2026 07:51
@nwparker nwparker changed the title feat(editor): syntax highlighting for Glimmer and Handlebars feat(editor): syntax highlighting for Glimmer .gjs/.gts files Oct 28, 2026
@nwparker
nwparker merged commit d155cfb into stablyai:main Oct 28, 2026
43 checks passed
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.

4 participants