`FileReport.language` is ignored for syntax highlighting
I recently attempted to use mutation-testing-elements to display cargo-mutants results. (Related discussion there)
This entry in the schema lead me to believe I could just set the required language property to "rust", ensure that prismjs/components/prism-rust is loaded and get syntax highlighting:
https://github.com/stryker-mutator/mutation-testing-elements/blob/3b88bf7c702935744112812c8755dbbecae421e9/packages/report-schema/src/mutation-testing-report-schema.json#L25-L33
However, after a lot of debugging around prism itself, I found out that the language property is not passed to rust and instead the language is inferred from the file extension by determineLanguage, which has a limited list of cases.
As it stands, to add the highlighting I had to patch mutation-testing-elements in one of two ways:
- either extend
determineLanguagewith a new case, - or change
highlightCodeto accept a language instead of a file name and passthis.model.languageinFileComponenthere.
For my experiment I chose the second option. I think this is a better interface, as language is a mandatory field anyways and just loading the right prismjs package and setting the language is something the user of the component can do without having to modify mutation-testing-elements itself.
However, this did break a bunch of tests around TestFiles and maybe the file extension should be used as a fallback or alternative option. I can see there was related discussion in #1503, though I think that relates only to test files.
Hi! Each prism language highlighting plugin is loaded separately in https://github.com/stryker-mutator/mutation-testing-elements/blob/master/packages/elements/src/style/prism-plugins.ts. This is because we don't want to load in all prism languages, as that would bloat the bundle considerably.
Since mutation-testing-elements is bundled into a single static JS file for the browser, we can't dynamically load language highlighting. However, since mutation-testing-elements encourages other mutation testing frameworks to use the format and its HTML report, you are more than welcome to add Rust as one of the loaded languages in the HTML report (option 1)! A PR for that could probably be merged and released pretty quickly. Don't forget to add a new icon as well in https://github.com/stryker-mutator/mutation-testing-elements/blob/master/packages/elements/src/components/file-icon/file-icon.component.ts
For your second suggestion, I think it does make sense to use the language from the fileResult to determine a language. Maybe we could still try the extension as a fallback for frameworks that didn't properly fill it in? That also wouldn't break anything. If you prefer, it can be separate from any rust highlighting support