Repository navigation
Highlight more languages in the source view - #6475
Conversation
There was a problem hiding this comment.
🟡 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
| // Paths with a URL scheme, like https:// or file://, belong to web content. | ||
| const URL_SCHEME_REGEXP = /^[a-z][a-z0-9+.-]*:\/\//i; |
mstange
left a comment
There was a problem hiding this comment.
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 Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
|
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.
e364f3e to
18ee95b
Compare
|
Rebased on main and resolved the conflicts with the find bar and the pretty-print changes in |
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

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-dataand loads that language on demand, each one in its own chunk..hh,.hxx,.mts,.ctsand.cjsto those lists so they don't go through the lazy path.https://,file://, ...) keep the JavaScript fallback. Inline scripts use the page URL as their path, which can end in.htmlor.md, and script URLs often end in a query string like?ver=3.7.1(language-data maps.1to.9to Troff).Bundle size
Production build, minified, from the esbuild metafile, measured on
33f0c4b(the branch is now rebased onaacb9f3; the five newer commits don't touch the source view or its dependencies):@lezer/common, which the main bundle already includes through@lezer/javascript, keeping more of its exports.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 fewLanguageDescription.of(...)entries for languages that actually show up in profiles (Python, Java, Kotlin, Go, Swift, C#...). Happy to do whichever you prefer.Other changes
@codemirror/autocomplete,@lezer/commonand@lezer/lr. I merged each into a single entry (the newer version, which satisfies all the ranges);yarn install --frozen-lockfileaccepts it.import(), which Jest can't run, so Jest uses the ESM build and Babel turns those calls intorequire().Testing
src/test/components/SourceViewEditor.test.ts. On main 3 of its 8 tests fail (Python, matchingDockerfileby 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-checkandyarn test-lockfilepass.yarn test(on33f0c4b) passes except threeWindowTitletests 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 lintandyarn test-lockfileagain.yarn start, opened the profile attached to the issue and double-clickedcpu_workto opent.py. Before, everything after the/*in the docstring is treated as a JS comment; after, it's highlighted as Python:Before:

After:
