дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-11-24 18:34:38 +02:00
fix(editor): colour Java primitive types as keywords (#5543)
@lezer/java tags PrimitiveType as standard(typeName), so int/long/boolean/... used the built-in colour instead of the keyword colour IntelliJ uses (void already had it). JAVA_TAGS now tags PrimitiveType as keyword; this covers Java files, JSP scriptlets and java code blocks in Markdown. Co-authored-by: wildcatDownstairs <[email protected]>
Цей коміт міститься в:
1 джерело
2f6bb7e995
коміт
1f8eaec00a
3 files changed
+20
-4
No files matched your search
@@ -120,7 +120,7 @@ describe("JSP pages", () => {
|
||||
"%>:pi",
|
||||
"<%!:pi",
|
||||
"private:keyword",
|
||||
"int:type",
|
||||
"int:keyword",
|
||||
"count:def",
|
||||
"0:num",
|
||||
"%>:pi",
|
||||
|
||||
@@ -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<string, Set<string>>();
|
||||
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"],
|
||||
|
||||
@@ -495,11 +495,11 @@ const CSS_TAGS: Parameters<typeof styleTags>[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<typeof styleTags>[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,
|
||||
};
|
||||
|
||||
Reference in new issue
Заблокувати користувача