fix(editor): leave Java statement labels uncoloured, as IntelliJ does (#5564)

Co-authored-by: LU XIANGRUI <[email protected]>
Цей коміт міститься в:
LU XIANGRUIтаLU XIANGRUI authored and GitHub committed 2026-11-24 14:54:09 +08:00
1 джерело 51766249f9
коміт 1205ffecd2
2 files changed
+25

No files matched your search

+23
Переглянути файл
@@ -411,6 +411,29 @@ describe("language modes", () => {
}
});
it("leaves Java statement labels uncoloured, unlike JavaScript's", async () => {
const highlighter = tagHighlighter([
{ tag: t.labelName, class: "label" },
{ tag: t.variableName, class: "variable" },
]);
const labels = async (mode: string, path: string, doc: string) => {
const support = await loadSupport(findLanguageDescription(mode, path)!);
const found: string[] = [];
highlightTree(support!.language.parser.parse(doc), highlighter, (from, to, style) =>
found.push(`${doc.slice(from, to)}:${style}`),
);
return found.filter((s) => s.startsWith("outer"));
};
expect(await labels("Java", "/p/A.java", "class A { void f() { outer: for (;;) { break outer; } } }")).toEqual([
"outer:variable",
"outer:variable",
]);
expect(await labels("JavaScript", "/p/a.js", "outer: for (;;) { break outer; }")).toEqual([
"outer:label",
"outer:label",
]);
});
it("recognizes go.mod and go.work files by mode and filename", async () => {
for (const [mode, path] of [
["GoMod", "/project/go.mod"],
+2
Переглянути файл
@@ -495,6 +495,8 @@ const CSS_TAGS: Parameters<typeof styleTags>[0] = {
export const JAVA_TAGS: Parameters<typeof styleTags>[0] = {
"MarkerAnnotation/Identifier Annotation/Identifier MarkerAnnotation Annotation": t.annotation,
this: t.keyword,
// IntelliJ has no Java label colour: `outer:` stays plain text, like `break outer`.
Label: t.variableName,
};
// @lezer/go leaves `default` uncoloured, unlike `case` and `switch`.