Skip to content

Commit 80a2351

Browse files
Yuruzuuclaudemaria-rcks
authored
fix(web,mobile): Luau files are syntax highlighted in diffs (#25865)
Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: maria-rcks <[email protected]> Co-authored-by: maria-rcks <[email protected]>
1 parent 59bb4e8 commit 80a2351

4 files changed

Lines changed: 39 additions & 2 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { describe, expect, it } from "vite-plus/test";
2+
3+
import { resolveHighlightLanguage } from "./highlightLanguage";
4+
5+
describe("resolveHighlightLanguage", () => {
6+
it.each([
7+
["src/init.luau", "lua"],
8+
["styles/page.xsl", "xml"],
9+
["styles/page.xslt", "xml"],
10+
])("%s highlights as %s", (path, language) => {
11+
expect(resolveHighlightLanguage({ path })).toBe(language);
12+
});
13+
});

‎apps/mobile/src/lib/highlightLanguage.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
import "@t3tools/client-runtime/assembly-highlighting";
2-
import { getFiletypeFromFileName } from "@pierre/diffs/utils/getFiletypeFromFileName";
2+
import {
3+
getFiletypeFromFileName,
4+
setCustomExtension,
5+
} from "@pierre/diffs/utils/getFiletypeFromFileName";
36

47
import { HIGHLIGHTS_LANGUAGE_IDS } from "./highlights.generated";
58

9+
// Highlights has no lexer for these dialects, so they use their base language's.
10+
setCustomExtension("luau", "lua");
11+
setCustomExtension("xsl", "xml");
12+
setCustomExtension("xslt", "xml");
13+
614
/** The native lexer ID for a @pierre/highlights language name, or 0 (plain text). */
715
export function highlightLanguageId(language: string): number {
816
return Object.hasOwn(HIGHLIGHTS_LANGUAGE_IDS, language) ? HIGHLIGHTS_LANGUAGE_IDS[language]! : 0;

‎apps/web/src/lib/syntaxHighlighting.test.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
import { getFiletypeFromFileName } from "@pierre/diffs";
2-
import { expect, it } from "vite-plus/test";
2+
import { describe, expect, it } from "vite-plus/test";
33

44
import { getSyntaxHighlighterPromise } from "./syntaxHighlighting";
55
import { DIFF_THEME_NAMES } from "./diffRendering";
66

7+
describe("dialect file types", () => {
8+
it.each([
9+
["src/init.luau", "lua"],
10+
["styles/page.xsl", "xml"],
11+
["styles/page.xslt", "xml"],
12+
])("%s highlights as %s", (path, language) => {
13+
expect(getFiletypeFromFileName(path)).toBe(language);
14+
});
15+
});
16+
717
it.each([
818
"asm",
919
"assembly",

‎apps/web/src/lib/syntaxHighlighting.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
import "@t3tools/client-runtime/assembly-highlighting";
22
import {
33
getSharedHighlighter,
4+
setCustomExtension,
45
type DiffsHighlighter,
56
type HighlighterTypes,
67
type SupportedLanguages,
78
} from "@pierre/diffs";
89

910
import { DIFF_THEME_NAMES } from "./diffRendering";
1011

12+
// Highlights has no lexer for these dialects, so they use their base language's.
13+
setCustomExtension("luau", "lua");
14+
setCustomExtension("xsl", "xml");
15+
setCustomExtension("xslt", "xml");
16+
1117
/**
1218
* Highlights' hand-written WASM lexers tokenize large files 10-40x faster than
1319
* Shiki and never backtrack like Shiki's JS regex engine. Only one highlighter

0 commit comments

Comments
 (0)