diff --git a/src/editor/core/cm/jsp/jsp.test.ts b/src/editor/core/cm/jsp/jsp.test.ts index 64d09bab8..9cd2bb146 100644 --- a/src/editor/core/cm/jsp/jsp.test.ts +++ b/src/editor/core/cm/jsp/jsp.test.ts @@ -120,7 +120,7 @@ describe("JSP pages", () => { "%>:pi", "<%!:pi", "private:keyword", - "int:type", + "int:keyword", "count:def", "0:num", "%>:pi", diff --git a/src/editor/core/cm/languages.test.ts b/src/editor/core/cm/languages.test.ts index 805c11196..2a14963ec 100644 --- a/src/editor/core/cm/languages.test.ts +++ b/src/editor/core/cm/languages.test.ts @@ -510,6 +510,22 @@ describe("language modes", () => { ]); }); + it("colours Java primitive types as keywords", async () => { + const highlighter = tagHighlighter([ + { tag: t.keyword, class: "keyword" }, + { tag: t.standard(t.typeName), class: "builtin-type" }, + ]); + const primitives = ["int", "long", "double", "float", "boolean", "char", "byte", "short"]; + const doc = `class A { ${primitives.map((p, i) => `${p} f${i};`).join(" ")} void m() { int[] a = new int[1]; } }`; + const support = await loadSupport(findLanguageDescription("Java", "/p/A.java")!); + const styles = new Map>(); + highlightTree(support!.language.parser.parse(doc), highlighter, (from, to, style) => { + const text = doc.slice(from, to); + styles.set(text, (styles.get(text) ?? new Set()).add(style)); + }); + for (const word of [...primitives, "void"]) expect([...(styles.get(word) ?? [])], word).toEqual(["keyword"]); + }); + it("recognizes go.mod and go.work files by mode and filename", async () => { for (const [mode, path] of [ ["GoMod", "/project/go.mod"], diff --git a/src/editor/core/cm/languages.ts b/src/editor/core/cm/languages.ts index 00b3a1f8f..cee2e58c4 100644 --- a/src/editor/core/cm/languages.ts +++ b/src/editor/core/cm/languages.ts @@ -495,11 +495,11 @@ const CSS_TAGS: Parameters[0] = { "ClassName IdName PseudoClassName ColorLiteral CallTag": t.tagName, }; -// @lezer/java tags annotations as plain identifiers, and `this` as `self` (Python's `self` colour); -// IntelliJ colours `this` as a keyword. +// @lezer/java tags annotations as plain identifiers, `this` as `self` (Python's `self` colour) and +// primitive types as built-in types; IntelliJ colours `this` and `int`, `boolean`… as keywords. export const JAVA_TAGS: Parameters[0] = { "MarkerAnnotation/Identifier Annotation/Identifier MarkerAnnotation Annotation": t.annotation, - this: t.keyword, + "this PrimitiveType": t.keyword, // IntelliJ has no Java label colour: `outer:` stays plain text, like `break outer`. Label: t.variableName, };