Skip to content

Highlight more languages in the source view - #6475

Merged
fatadel merged 1 commit into
firefox-devtools:mainfrom
zuhairkhalid229:source-view-more-languages
Nov 27, 2026
Merged

fatadel merged 1 commit into
firefox-devtools:mainfrom
zuhairkhalid229:source-view-more-languages

Conversation

@zuhairkhalid229

@zuhairkhalid229 zuhairkhalid229 commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Main | Deploy preview

Fixes #6436.

The source view only knew Rust, C++ and JS/TS and showed everything else as JavaScript. For local file paths it now looks the file name up in @codemirror/language-data and loads that language on demand, each one in its own chunk.

  • Rust, C++ and JS/TS stay bundled and highlight right away. I added .hh, .hxx, .mts, .cts and .cjs to those lists so they don't go through the lazy path.
  • Paths with a URL scheme (https://, file://, ...) keep the JavaScript fallback. Inline scripts use the page URL as their path, which can end in .html or .md, and script URLs often end in a query string like ?ver=3.7.1 (language-data maps .1 to .9 to Troff).
  • If the file changes while a language is still loading, the late result is ignored. If loading fails, it falls back to JavaScript as before.

Bundle size

Production build, minified, from the esbuild metafile, measured on 33f0c4b (the branch is now rebased on aacb9f3; the five newer commits don't touch the source view or its dependencies):

main bundle opening the source view all dist output
main 1563.4 KB 388.2 KB 3202 KB, 20 files
this PR 1570.8 KB 418.2 KB 4179 KB, 146 files
  • Main bundle +7.4 KB: 0.6 KB comes from the lockfile change below. The rest is @lezer/common, which the main bundle already includes through @lezer/javascript, keeping more of its exports.
  • Opening the source view: +30 KB, mostly language-data's 15.7 KB list of languages. JS, Rust and C++ are now separate chunks, so that's 7 requests instead of 2.
  • Every other language is its own chunk, fetched only when a file needs it (Python is 44 KB).

The part to weigh: the service worker precaches everything in dist/, so the ~120 new language chunks (940 KB, about 374 KB gzipped) would be downloaded once by every visitor. If that's too much, I can replace the full list with a few LanguageDescription.of(...) entries for languages that actually show up in profiles (Python, Java, Kotlin, Go, Swift, C#...). Happy to do whichever you prefer.

Other changes

  • yarn.lock: adding the package left second copies of @codemirror/autocomplete, @lezer/common and @lezer/lr. I merged each into a single entry (the newer version, which satisfies all the ranges); yarn install --frozen-lockfile accepts it.
  • jest.config.js: the CommonJS build of language-data uses a native import(), which Jest can't run, so Jest uses the ESM build and Babel turns those calls into require().

Testing

  • New src/test/components/SourceViewEditor.test.ts. On main 3 of its 8 tests fail (Python, matching Dockerfile by file name, .hh); with this change all pass. Taking out the URL check, matching on the whole path, or taking out the stale-load check each makes the matching test fail.
  • yarn ts, yarn lint, yarn license-check and yarn test-lockfile pass. yarn test (on 33f0c4b) passes except three WindowTitle tests that fail the same way on main on my machine (Windows with en-GB date formatting). After rebasing I ran the new tests, yarn ts, yarn lint and yarn test-lockfile again.
  • I ran yarn start, opened the profile attached to the issue and double-clicked cpu_work to open t.py. Before, everything after the /* in the docstring is treated as a JS comment; after, it's highlighted as Python:

Before:
before-master

After:
after-fix

Copilot AI balanced review requested due to automatic review settings November 21, 2026 22:14

Copilot AI 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.

🟡 Changes recommended

URL scheme detection misses schemes without //, causing inline scripts at jar: URLs to receive HTML highlighting instead of JavaScript.

1 open issue
What changed in this PR

Expands the profiler’s source-view syntax highlighting beyond Rust, C++, and JavaScript/TypeScript, addressing #6436 through CodeMirror’s language catalog.

Changes:

  • Adds filename-based language detection and on-demand loading while retaining bundled-language fast paths.
  • Adds JavaScript fallback on load failure and protection against stale language loads.
  • Adds highlighting tests and updates Jest configuration and dependencies.
File Description
yarn.lock Locks added language packages and consolidates shared dependencies.
src/​test/​components/​SourceViewEditor.test.ts Tests language detection, URL fallback, and stale-load protection.
src/​components/​shared/​SourceView-codemirror.ts Implements expanded language detection and asynchronous loading.
package.json Adds @codemirror/language-data.
jest.config.js Enables Jest to transform language-data’s dynamic imports.

Review effort: Balanced

Comment on lines +53 to +54
// Paths with a URL scheme, like https:// or file://, belong to web content.
const URL_SCHEME_REGEXP = /^[a-z][a-z0-9+.-]*:\/\//i;

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

I think that all sounds good to me. Thanks for keeping an eye on the main bundle size. Downloading more into the service worker cache is fine, it's not a lot in the grand scheme of things and it happens asynchronously, it doesn't block the UI from being usable on first load.

@codecov

codecov Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.88889% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.23%. Comparing base (bfe94af) to head (18ee95b).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/components/shared/SourceView-codemirror.ts 88.88% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6475      +/-   ##
==========================================
+ Coverage   85.21%   85.23%   +0.01%     
==========================================
  Files         372      372              
  Lines       40690    40722      +32     
  Branches    11659    11667       +8     
==========================================
+ Hits        34675    34708      +33     
+ Misses       5575     5574       -1     
  Partials      440      440              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@canova

canova commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Hi @zuhairkhalid229, thanks for the PR. Could you rebase your PR on top of recent main and resolve the conflicts so we can merge it?

Local files that aren't Rust, C++ or JavaScript/TypeScript now look up
their language by file name in @codemirror/language-data, which loads
each language on demand into its own chunk. Paths with a URL scheme keep
the JavaScript fallback, since inline scripts use the page URL as their
path and script URLs often end in a query string.
@zuhairkhalid229
zuhairkhalid229 force-pushed the source-view-more-languages branch from e364f3e to 18ee95b Compare November 26, 2026 22:41
@zuhairkhalid229

Copy link
Copy Markdown
Contributor Author

Rebased on main and resolved the conflicts with the find bar and the pretty-print changes in SourceView-codemirror.ts and package.json. The new test passes the find-bar callback the constructor takes now. The source view tests (171, including the find bar and pretty-print ones), yarn ts, yarn lint and yarn test-lockfile pass locally.

@fatadel
fatadel added this pull request to the merge queue Nov 27, 2026
Merged via the queue into firefox-devtools:main with commit 89527cf Nov 27, 2026
23 checks passed
@fatadel fatadel mentioned this pull request Dec 1, 2026
fatadel added a commit that referenced this pull request Dec 1, 2026
Changes:

[canova] Add localization guidelines to AGENTS.md (#6487)
[staktrace] Add markers to represent causal flows (#6488)
[zuhairkhalid229] Highlight more languages in the source view (#6475)
[kayaal34] Fix typos in developer docs (#6479)
[fatadel] Remove the search field hint (#6490)
[mstange] Add an interactive mode for profiler-cli (#6400)
[mstange] Make keyboard zooming in chart viewports center on the mouse position. (#6471)
[fatadel] Bump profiler-cli version to 0.16.0 (#6502)

And special thanks to our localizers:

de: Michael Köhler
el: Jim Spentzos
en-GB: Ian Neal
ia: Melo46
it: Francesco Lodolo
nl: Mark Heijl
ru: berry, Valery Ledovskoy
sv-SE: Andreas Pettersson
tr: Grk, Selim Şumlu
zh-TW: Pin-guang Chen
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.

Support more languages in source view

5 participants