Skip to content

fix(editor): recognize all bundled Monaco language associations - #23371

Merged
nwparker merged 1 commit into
mainfrom
nwparker/monaco-langs
Sep 27, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/monaco-langs

Conversation

@nwparker

@nwparker nwparker commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​76 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​76
Prod 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​608 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​607

ELI5

Files such as Bicep, WGSL, Pascal, and reStructuredText opened as plain text even though Orca already bundled their highlighting. Recognize every filename association shipped by Monaco so these no longer need one-language PRs.

What Changed

Added a small generated metadata file covering all 90 built-in registrations in Monaco 0.55.1, including the 81 with filenames or extensions. Filename detection keeps Orca's existing choices first, then uses Monaco's exact filenames and longest matching extensions. Ambiguous extensions follow upstream registration order (.pp selects Ruby). Prototype property names such as constructor safely remain plain text.

The generator reads the installed package's registration syntax without executing grammars. A drift test requires regeneration when Monaco changes. Cloned microsoft/monaco-editor at v0.55.1 (516f350bdaf7a82f6731bd128a9ec86a6e5fa47d) to inspect the authoritative registrations and lazy loading. Regeneration instructions are in docs/reference/monaco-language-associations.md.

Why

Orca already imports Monaco's full language entry point; its separate handwritten filename table was the gap. Generated metadata avoids adding more one-off rows and avoids importing the full editor during session restoration. Grammars still load on demand. Existing custom languages, previews, and .mdx → Markdown behavior are preserved. Languages with no filename association cannot be inferred from paths; this does not add language servers or change mobile's separate grammar set.

Linked Issue

Follow-up to #20928, now merged; related to #13835.

Visual Proof

Real Orca editor in a hidden Electron instance on macOS, same Bicep file in a folder workspace. Before uses the base branch detector; after uses this branch, including session restoration. The file was opened through the file tree. Verified the model language changed from plaintext to bicep and inspected rendered token colors.

Before After
Plain text Bicep highlighting

Testing

  • I manually tested these changes locally
  • Automated tests added/updated

107 tests passed across filename detection, all unambiguous upstream associations, Solidity registration, and generated metadata drift. Coverage includes Windows/UNC paths, remote-style paths, folder names containing extensions, custom overrides, unknown names, and .pp precedence.

pnpm tc:web and pnpm run check:code-quality:changed passed. Hidden Electron dev build and CDP rendered check passed. Native Windows/Linux and a live SSH host were not exercised; detection is renderer-only and host-independent. Full build and broader test suite left to CI.

Review

Self-reviewed registration extraction, precedence, lazy loading, and path handling.

Agent skill upstream boundary

  • Not applicable: no agent skill sources or artifacts changed.

Notes

No IPC, remote protocol, filesystem access, new dependencies, or grammar imports are added to the renderer. The generated JSON is approximately 8 KB before bundling. Existing Monaco grammar behavior still applies.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • Before/after screenshots attached
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered
  • Full lint, typecheck, test, and build suite (CI; focused local checks listed above)

Community credit and related work

Thanks to @anajuliabit for the Solidity fix in #20928 that prompted this broader solution; @psh4607 for the XAML mapping and regression cases in #16530; and @smaucy for reporting the XAML gap in #16396. This PR covers both XAML cases, including uppercase Windows paths, through Monaco's own XML associations.

Also thanks to @randyc-kh for #11215 and @albarracin-jorge for #13236: this change covers .tfvars and .hbs/.handlebars, respectively. Those items remain open because justfiles and Glimmer .gjs/.gts require additional work. Thanks to @el-analista for #19968: .jl now selects Monaco's built-in Julia grammar, but richer Julia tokenization is a separate request and remains open.

@coderabbitai

coderabbitai Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 977830c4-bfb3-4d84-9344-3658bc2cd912

📥 Commits

Reviewing files that changed from the base of the PR and between 90bae01 and e2fc10b.

📒 Files selected for processing (7)
  • config/scripts/generate-monaco-associations.mjs
  • config/scripts/generate-monaco-associations.test.mjs
  • docs/reference/monaco-language-associations.md
  • src/renderer/src/lib/language-detect.ts
  • src/renderer/src/lib/monaco-filename-language.test.ts
  • src/renderer/src/lib/monaco-filename-language.ts
  • src/renderer/src/lib/monaco-language-associations.json

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.


📝 Walkthrough

Walkthrough

The changes add a script that extracts Monaco language IDs, extensions, and filenames into a JSON catalog. They add a test that compares the generated registrations with the catalog, and documentation for its source and matching rules. Renderer language detection now checks the catalog after existing filename and extension mappings and before its dotenv and plaintext fallbacks.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to e2fc1

The filename-association change appears ready to merge after normal checks.

Architecture Summary

Architecture risk: 🟡 Medium · up to e2fc1

The change affects 3 systems.

Changed systems: src, config, docs

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — src (service) was modified; 4 changed files map to changed impact.
  • observed — config (service) was modified; 2 changed files map to changed impact.
  • observed — docs (service) was modified; 1 changed file maps to changed impact.

Before / after behavior

  • observed — Modified behavior in config/scripts/generate-monaco-associations.mjs: Adds Node.js and TypeScript API imports, resolves Monaco’s editor entry point, and exports the destination path for the language-associations JSON file.
  • observed — Modified behavior in config/scripts/generate-monaco-associations.mjs: Adds readMonacoAssociations(), which parses the editor entry point to find imported .contribution.js files, then traverses each file for registerLanguage or languages.register calls. It extracts literal id, extensions, and filenames values; unsupported arguments or values, nonliteral association entries, missing IDs, and fewer than 80 registrations cause errors.
  • observed — Modified behavior in config/scripts/generate-monaco-associations.mjs: When the script is invoked directly, it writes the extracted registrations as indented JSON with a trailing newline to associationsPath.
  • observed — Modified behavior in config/scripts/generate-monaco-associations.test.mjs: Adds a test asserting that the associations file matches the registrations returned by readMonacoAssociations(), with a mismatch message directing users to run the generator after upgrading Monaco.

Reliability and maintainability

  • inferred — Risk-relevant change factors for src: blast_radius_1; direct_dependents_1
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 5 files. (2 skipped: 2… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 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 and concisely describes the primary change: recognizing all bundled Monaco language associations in the editor.
Description check ✅ Passed The description covers the required sections, including the user impact, implementation, rationale, linked issues, visual proof, testing, review notes, compatibility considerations, and checklist. It …
Full details: Docstring Coverage

Explanation

Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 5 files. (2 skipped: 2 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

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.

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

Adds a generated metadata file covering Monaco's built-in language filename/extension associations and consults it as a fallback in detectLanguage, so bundled languages (Bicep, WGSL, Pascal, reStructuredText, Cypher, F# …) no longer open as plaintext.

  • Generated association metadata — monaco-language-associations.json holds all 90 registrations from the installed Monaco 0.55.1 entry point, produced by a generator that parses *.contribution.js syntax trees without executing grammars; a drift test forces regeneration on upgrade.
  • Filename detection fallback — monaco-filename-language.ts builds lowercase filename/extension maps and resolves exact filenames before the longest extension, matching Monaco's own precedence and last-registration-wins rule (.pp → ruby).
  • detectLanguage integration — the fallback sits after Orca's EXT_TO_LANGUAGE and before the dotenv branch, preserving custom languages and .env.* handling; FILENAME_TO_LANGUAGE[filename] became Object.hasOwn(...) so prototype names (constructor, __proto__) no longer leak the Object prototype.
  • Tests and docs — renderer tests pin all unambiguous upstream associations, .pp precedence, Windows/UNC/remote paths, and preserved Orca behavior.

Beyond reading the diff I verified the load-bearing claims: the direct .contribution.js imports of editor.main.js contain exactly 90 registerLanguage/languages.register({ call sites and the JSON has 90 entries, so the generator is complete relative to the entry point; and languagesAssociations.js#getAssociationByPath confirms Monaco resolves exact filename before the longest extension with later registrations winning, which this implementation mirrors. The generator drift test, monaco-filename-language tests, language-detect tests, tc:web, oxlint on the touched files, and oxfmt --check on the JSON all pass.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@nwparker

Copy link
Copy Markdown
Contributor Author

Verified the unchanged head e2fc10b: all 107 focused tests pass again, plus a targeted check reproducing both XAML cases from #16530 and confirming the scope of related requests. The earlier hidden Electron validation on this exact head showed Bicep changing from plaintext to real colored tokens; before/after screenshots are attached in the description. CI static analysis, typecheck, and Linux/Windows packaging have passed; remaining unit-test shards are still running.

Reviewed the open language PRs/issues before closing duplicates. Only #16530 / #16396 are fully covered. Custom grammars (CUDA, VHDL, Nix, OCaml, Godot, VCL, Quarto, MATLAB/LaTeX), JSP improvements, mobile highlighting, and user grammar loading remain separate work. Community credits are now in the description.

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