дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-04 09:11:10 +02:00
feat(editor): style Java static, constant and final fields separately (#7930)
Java fields get their own colour scheme attributes under Java > Class Fields: instance field, instance final field, static field and constant (static final field), each falling back through the field kind it refines to Language Defaults > Identifiers > Static field / Instance field. Interface fields count as constants. The resolver and settings preview follow the whole inherit chain; .icls import maps the matching attributes. Fixes #7643
Цей коміт міститься в:
1 джерело
d62c978032
коміт
d55f116add
16 files changed
+247
-29
No files matched your search
@@ -0,0 +1,37 @@
|
||||
import { EditorView } from "@codemirror/view";
|
||||
import { commands } from "../src/platform/ipc";
|
||||
import { setInvokeRoute } from "../src/platform/tauriCore";
|
||||
import { schemeCss } from "../src/platform/colorScheme";
|
||||
import { lspDoc } from "../src/editor/lsp/lsp";
|
||||
import { semanticExtension } from "../src/editor/lsp/semantic";
|
||||
import { lspTheme } from "../src/editor/lsp/theme";
|
||||
|
||||
// jdtls's tokens for four fields, one per line: instance, instance final, static, static final.
|
||||
setInvokeRoute(() => null);
|
||||
commands.lspSemanticTokens = async () => ({
|
||||
status: "ok",
|
||||
data: {
|
||||
tokenTypes: ["property"],
|
||||
tokenModifiers: ["static", "readonly"],
|
||||
data: [0, 0, 5, 0, 0, 1, 0, 4, 0, 2, 2, 0, 6, 0, 1, 3, 0, 3, 0, 3],
|
||||
},
|
||||
});
|
||||
const style = document.createElement("style");
|
||||
style.textContent = schemeCss("dark", {
|
||||
dark: {
|
||||
staticField: { foreground: "#9876aa" },
|
||||
"java.staticFinalField": { bold: true },
|
||||
"java.instanceFinalField": { foreground: "#cc7832" },
|
||||
},
|
||||
});
|
||||
document.head.append(style);
|
||||
new EditorView({
|
||||
parent: document.body,
|
||||
doc: "count\ncode\nactive\nMAX",
|
||||
extensions: [
|
||||
EditorView.editorAttributes.of({ "data-language": "Java" }),
|
||||
lspTheme,
|
||||
lspDoc.of({ doc: 1, path: "A.java", language: "java", uiMode: "Java", readOnly: false }),
|
||||
semanticExtension(),
|
||||
],
|
||||
});
|
||||
@@ -0,0 +1,9 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
</head>
|
||||
<body>
|
||||
<script type="module" src="./javaFieldStyle.fixture.ts"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,25 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
|
||||
test("Java Class Fields styles apply per field kind and fall back to the Language Defaults (#7643)", async ({
|
||||
page,
|
||||
}) => {
|
||||
await page.goto("/e2e/javaFieldStyle.html");
|
||||
const instance = page.locator(".cm-sem-java-instance-field");
|
||||
const instanceFinal = page.locator(".cm-sem-java-instance-final-field");
|
||||
const staticField = page.locator(".cm-sem-java-static-field");
|
||||
const constant = page.locator(".cm-sem-java-constant");
|
||||
await expect(constant).toHaveText("MAX");
|
||||
|
||||
// Only the constant is bold; both static kinds keep the Language Defaults static field colour and italic.
|
||||
await expect(constant).toHaveCSS("font-weight", "700");
|
||||
await expect(constant).toHaveCSS("font-style", "italic");
|
||||
await expect(constant).toHaveCSS("color", "rgb(152, 118, 170)");
|
||||
await expect(staticField).toHaveCSS("font-weight", "400");
|
||||
await expect(staticField).toHaveCSS("font-style", "italic");
|
||||
await expect(staticField).toHaveCSS("color", "rgb(152, 118, 170)");
|
||||
// Instance fields stay upright; the final one has its own colour.
|
||||
await expect(instance).toHaveCSS("font-style", "normal");
|
||||
await expect(instance).toHaveCSS("font-weight", "400");
|
||||
await expect(instanceFinal).toHaveCSS("color", "rgb(204, 120, 50)");
|
||||
await expect(instanceFinal).toHaveCSS("font-style", "normal");
|
||||
});
|
||||
@@ -32,7 +32,9 @@ describe("semanticRanges", () => {
|
||||
expect(semanticRanges(doc, input, false, "python")[0]?.className).toBe(
|
||||
"cm-sem-property cm-sem-static cm-sem-python-static",
|
||||
);
|
||||
expect(semanticRanges(doc, input, false, "java")[0]?.className).toBe("cm-sem-property cm-sem-static");
|
||||
expect(semanticRanges(doc, input, false, "java")[0]?.className).toBe(
|
||||
"cm-sem-property cm-sem-static cm-sem-java-static-field",
|
||||
);
|
||||
});
|
||||
|
||||
it("routes Python library symbols through its built-in name colour", () => {
|
||||
|
||||
@@ -25,12 +25,12 @@ const named = (ranges: Array<{ from: number; to: number; className: string }>) =
|
||||
describe("javaDeclarationRanges", () => {
|
||||
it("colours declaration names as jdtls does, and nothing else", () => {
|
||||
expect(named(javaDeclarationRanges(tree))).toEqual({
|
||||
count: "cm-sem-property cm-sem-declaration",
|
||||
total: "cm-sem-property cm-sem-declaration",
|
||||
name: "cm-sem-property cm-sem-static cm-sem-declaration",
|
||||
code: "cm-sem-property cm-sem-declaration",
|
||||
SERIAL: "cm-sem-property cm-sem-static cm-sem-declaration",
|
||||
MAX: "cm-sem-property cm-sem-static cm-sem-declaration",
|
||||
count: "cm-sem-property cm-sem-declaration cm-sem-java-instance-field",
|
||||
total: "cm-sem-property cm-sem-declaration cm-sem-java-instance-field",
|
||||
name: "cm-sem-property cm-sem-static cm-sem-declaration cm-sem-java-static-field",
|
||||
code: "cm-sem-property cm-sem-declaration cm-sem-java-instance-final-field",
|
||||
SERIAL: "cm-sem-property cm-sem-static cm-sem-declaration cm-sem-java-constant",
|
||||
MAX: "cm-sem-property cm-sem-static cm-sem-declaration cm-sem-java-constant",
|
||||
A: "cm-sem-function cm-sem-declaration",
|
||||
helper: "cm-sem-function cm-sem-static cm-sem-declaration",
|
||||
id: "cm-sem-function cm-sem-declaration",
|
||||
@@ -38,7 +38,7 @@ describe("javaDeclarationRanges", () => {
|
||||
HIGH: "cm-sem-constant cm-sem-static cm-sem-declaration",
|
||||
f: "cm-sem-function cm-sem-declaration",
|
||||
Level: "cm-sem-function cm-sem-declaration",
|
||||
C: "cm-sem-property cm-sem-static cm-sem-declaration",
|
||||
C: "cm-sem-property cm-sem-static cm-sem-declaration cm-sem-java-constant",
|
||||
m: "cm-sem-function cm-sem-declaration",
|
||||
s: "cm-sem-function cm-sem-static cm-sem-declaration",
|
||||
});
|
||||
@@ -46,11 +46,13 @@ describe("javaDeclarationRanges", () => {
|
||||
|
||||
it("is shown without server tokens and gives way to them", () => {
|
||||
const empty = { data: [], tokenTypes: [], tokenModifiers: [] };
|
||||
expect(named(semanticRanges(doc, empty, false, "java", tree)).count).toBe("cm-sem-property cm-sem-declaration");
|
||||
expect(named(semanticRanges(doc, empty, false, "java", tree)).count).toBe(
|
||||
"cm-sem-property cm-sem-declaration cm-sem-java-instance-field",
|
||||
);
|
||||
// A jdtls token over `count` (line 1, col 14) replaces the fallback.
|
||||
const tokens = { data: [1, 14, 5, 0, 0], tokenTypes: ["property"], tokenModifiers: [] };
|
||||
const count = semanticRanges(doc, tokens, false, "java", tree).filter((r) => SRC.slice(r.from, r.to) === "count");
|
||||
expect(count.map((r) => r.className)).toEqual(["cm-sem-property"]);
|
||||
expect(count.map((r) => r.className)).toEqual(["cm-sem-property cm-sem-java-instance-field"]);
|
||||
});
|
||||
|
||||
it("matches the classes of jdtls's own declaration tokens", () => {
|
||||
|
||||
@@ -18,6 +18,13 @@ const DECLARATIONS: Record<string, readonly [string, string]> = {
|
||||
};
|
||||
|
||||
const isStatic = (decl: SyntaxNode) => decl.getChild("Modifiers")?.getChild("static") != null;
|
||||
const isFinal = (decl: SyntaxNode) => decl.getChild("Modifiers")?.getChild("final") != null;
|
||||
|
||||
/** IntelliJ's Java › Class Fields kind of a field (jdtls: the `static` and `readonly` modifiers). */
|
||||
export function javaFieldClass(isStaticField: boolean, isFinalField: boolean): string {
|
||||
if (isStaticField) return isFinalField ? "cm-sem-java-constant" : "cm-sem-java-static-field";
|
||||
return isFinalField ? "cm-sem-java-instance-final-field" : "cm-sem-java-instance-field";
|
||||
}
|
||||
|
||||
/**
|
||||
* Declaration names coloured from the parse tree while jdtls has not answered (startup, project import,
|
||||
@@ -31,7 +38,15 @@ export function javaDeclarationRanges(tree: Tree): SemanticRange[] {
|
||||
const classes = Object.hasOwn(DECLARATIONS, cursor.name) ? DECLARATIONS[cursor.name] : undefined;
|
||||
if (!classes) return;
|
||||
const decl = cursor.node;
|
||||
const className = classes[isStatic(decl) ? 1 : 0];
|
||||
const staticDecl = isStatic(decl);
|
||||
// Interface fields are implicitly `static final`.
|
||||
const field =
|
||||
cursor.name === "ConstantDeclaration"
|
||||
? javaFieldClass(true, true)
|
||||
: cursor.name === "FieldDeclaration"
|
||||
? javaFieldClass(staticDecl, isFinal(decl))
|
||||
: null;
|
||||
const className = field ? `${classes[staticDecl ? 1 : 0]} ${field}` : classes[staticDecl ? 1 : 0];
|
||||
const declarators = decl.getChildren("VariableDeclarator");
|
||||
for (const owner of declarators.length ? declarators : [decl]) {
|
||||
const name = owner.getChild("Definition");
|
||||
|
||||
@@ -40,6 +40,7 @@ describe("Java semantic tokens", () => {
|
||||
|
||||
it("keeps the other modifiers of JDK symbols", () => {
|
||||
expect(token("property", ["static", "defaultLibrary"], "java")?.sort()).toEqual([
|
||||
"cm-sem-java-static-field",
|
||||
"cm-sem-property",
|
||||
"cm-sem-static",
|
||||
]);
|
||||
@@ -49,11 +50,19 @@ describe("Java semantic tokens", () => {
|
||||
expect(token(type, ["static"], "java")).not.toContain("cm-sem-static");
|
||||
});
|
||||
|
||||
it("keeps static methods italic", () => {
|
||||
expect(token("method", ["static"], "java")?.sort()).toEqual(["cm-sem-function", "cm-sem-static"]);
|
||||
});
|
||||
|
||||
it.each([
|
||||
["property", "cm-sem-property"],
|
||||
["method", "cm-sem-function"],
|
||||
])("keeps static %s italic", (type, cls) => {
|
||||
expect(token(type, ["static"], "java")?.sort()).toEqual([cls, "cm-sem-static"]);
|
||||
[[], "cm-sem-java-instance-field"],
|
||||
[["readonly"], "cm-sem-java-instance-final-field"],
|
||||
[["static"], "cm-sem-java-static-field"],
|
||||
[["static", "readonly"], "cm-sem-java-constant"],
|
||||
])("gives a %j field its Class Fields kind (#7643)", (modifiers, kind) => {
|
||||
const classes = token("property", modifiers, "java");
|
||||
expect(classes).toContain(kind);
|
||||
expect(classes?.includes("cm-sem-static")).toBe(modifiers.includes("static"));
|
||||
});
|
||||
|
||||
it("keeps static types italic in other languages", () => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { Tree } from "@lezer/common";
|
||||
import type { Text } from "@codemirror/state";
|
||||
import { registerLanguageSemantics, type LanguageSemantics, type SemanticRange } from "../languages";
|
||||
import { javaDeclarationRanges } from "./declarations";
|
||||
import { javaDeclarationRanges, javaFieldClass } from "./declarations";
|
||||
import { javaEscapeRanges } from "./escapes";
|
||||
import { isReassignedAt } from "./reassigned";
|
||||
import { javaUnterminatedLiteralRanges } from "./unterminated";
|
||||
@@ -82,6 +82,7 @@ const javaSemantics: LanguageSemantics = {
|
||||
const s = classes.indexOf("cm-sem-static");
|
||||
if (s >= 0) classes.splice(s, 1);
|
||||
}
|
||||
if (type === "property") classes.push(javaFieldClass(modifiers.includes("static"), modifiers.includes("readonly")));
|
||||
if (Object.hasOwn(TYPE_KIND_CLASS, type)) classes.push(TYPE_KIND_CLASS[type]!);
|
||||
else if (type === "class" && modifiers.includes("abstract")) classes.push("cm-sem-java-abstract-class");
|
||||
if (tree && isReassignedAt(tree, doc, from)) classes.push("cm-sem-mutable");
|
||||
|
||||
@@ -135,6 +135,21 @@ function fallbackStyle(token: string, parents: string[]) {
|
||||
};
|
||||
}
|
||||
|
||||
/** A static field kind: unset, the Language Defaults static field (italic by default), then the instance field. */
|
||||
function staticFieldStyle(tokens: string[]) {
|
||||
const v = (names: string[], suffix: string, fallback: string) =>
|
||||
names.reduceRight((inner, name) => `var(--syn-${name}${suffix}, ${inner})`, fallback);
|
||||
const chain = [...tokens, "static-property"];
|
||||
return {
|
||||
color: v([...chain, "property"], "", "inherit"),
|
||||
fontWeight: v([...chain, "property"], "-bold", "inherit"),
|
||||
fontStyle: v([...chain, "static"], "-italic", "italic"),
|
||||
"--openidea-token-bg": v(chain, "-bg", "initial"),
|
||||
textDecoration: v(chain, "-effect", "none"),
|
||||
WebkitTextDecoration: v(chain, "-effect", "none"),
|
||||
};
|
||||
}
|
||||
|
||||
export const lspTheme = EditorView.theme({
|
||||
// --- completion (IDEA lookup: icon column, bold blue match, grey tail/type, advertiser) ---
|
||||
".cm-tooltip.cm-tooltip-autocomplete.cm-lsp-completion": {
|
||||
@@ -681,6 +696,17 @@ export const lspTheme = EditorView.theme({
|
||||
textDecoration: "var(--syn-static-property-effect, none)",
|
||||
WebkitTextDecoration: "var(--syn-static-property-effect, none)",
|
||||
},
|
||||
// IntelliJ's Java › Class Fields: unset, a final field keeps its field's style, and a field keeps
|
||||
// the Language Defaults instance / static field style.
|
||||
".cm-sem-property.cm-sem-java-instance-field": fallbackStyle("java-instance-field", ["property"]),
|
||||
".cm-sem-property.cm-sem-java-instance-final-field": fallbackStyle("java-instance-final-field", [
|
||||
"java-instance-field",
|
||||
"property",
|
||||
]),
|
||||
".cm-sem-property.cm-sem-static.cm-sem-java-static-field, .cm-sem-property.cm-sem-static.cm-sem-java-static-field *":
|
||||
staticFieldStyle(["java-static-field"]),
|
||||
".cm-sem-property.cm-sem-static.cm-sem-java-constant, .cm-sem-property.cm-sem-static.cm-sem-java-constant *":
|
||||
staticFieldStyle(["java-constant", "java-static-field"]),
|
||||
".cm-sem-python-static": { fontStyle: "var(--syn-python-static-italic, normal)" },
|
||||
".cm-sem-mutable": {
|
||||
textDecoration: "underline",
|
||||
|
||||
@@ -39,6 +39,7 @@ import {
|
||||
CLEAR_COLOR,
|
||||
listSchemes,
|
||||
customSchemes,
|
||||
inheritChain,
|
||||
type AttributeDef,
|
||||
} from "@/platform/colorScheme";
|
||||
import { HEX_COLOR } from "../../model/schema";
|
||||
@@ -196,11 +197,13 @@ function tokenStyle(attr: AttributeDef | undefined): CSSProperties {
|
||||
const italic = t === "comment" ? "var(--syn-comment-style)" : attr.defaultItalic ? "italic" : "inherit";
|
||||
const bold = attr.defaultBold ? "var(--fw-code-bold, 700)" : "inherit";
|
||||
const effect = attr.defaultEffect === "underline" ? "underline" : "none";
|
||||
// An inheriting token shows its parent's values while its own are unset.
|
||||
// An inheriting token shows its parent's values while its own are unset, and so on up the chain.
|
||||
const chain = inheritChain(attr);
|
||||
const v = (suffix: string, fallback?: string) =>
|
||||
attr.inherit
|
||||
? `var(--syn-${t}${suffix}, var(--syn-${attr.inherit}${suffix}${fallback ? `, ${fallback}` : ""}))`
|
||||
: `var(--syn-${t}${suffix}${fallback ? `, ${fallback}` : ""})`;
|
||||
chain.reduceRight<string | undefined>(
|
||||
(inner, name) => `var(--syn-${name}${suffix}${inner ? `, ${inner}` : ""})`,
|
||||
fallback,
|
||||
)!;
|
||||
return {
|
||||
color: v(""),
|
||||
fontWeight: v("-bold", bold) as CSSProperties["fontWeight"],
|
||||
@@ -362,6 +365,11 @@ const SAMPLES: Record<string, CodeSample> = {
|
||||
["0xff", "number"],
|
||||
[";", "operator"],
|
||||
],
|
||||
[
|
||||
[" static", "staticSymbol"],
|
||||
[" counter", "staticField"],
|
||||
[";", "operator"],
|
||||
],
|
||||
[
|
||||
[" field", "field"],
|
||||
[" = ", "operator"],
|
||||
@@ -766,21 +774,27 @@ const SAMPLES: Record<string, CodeSample> = {
|
||||
[
|
||||
[" private ", "java.keyword"],
|
||||
["Mode", "java.enum"],
|
||||
[" mode", "java.field"],
|
||||
[" mode", "java.instanceField"],
|
||||
[";", "java.operator"],
|
||||
],
|
||||
[
|
||||
[" private static ", "java.keyword"],
|
||||
["int", "java.keyword"],
|
||||
[" count", "java.staticField"],
|
||||
[";", "java.operator"],
|
||||
],
|
||||
[
|
||||
[" private static final ", "java.keyword"],
|
||||
["int", "java.keyword"],
|
||||
[" MAX", "java.constant"],
|
||||
[" MAX", "java.staticFinalField"],
|
||||
[" = ", "java.operator"],
|
||||
["3", "java.number"],
|
||||
[";", "java.operator"],
|
||||
],
|
||||
[
|
||||
[" private ", "java.keyword"],
|
||||
[" private final ", "java.keyword"],
|
||||
["String", "java.className"],
|
||||
[" name", "java.field"],
|
||||
[" name", "java.instanceFinalField"],
|
||||
[" = ", "java.operator"],
|
||||
['"a', "java.string"],
|
||||
["\\n", "java.escape"],
|
||||
@@ -802,7 +816,7 @@ const SAMPLES: Record<string, CodeSample> = {
|
||||
[" ", "text"],
|
||||
["System", "java.predefined"],
|
||||
[".", "java.operator"],
|
||||
["out", "java.field"],
|
||||
["out", "java.staticFinalField"],
|
||||
[".", "java.operator"],
|
||||
["println", "java.functionCall"],
|
||||
["(", "java.operator"],
|
||||
@@ -814,7 +828,7 @@ const SAMPLES: Record<string, CodeSample> = {
|
||||
[" ", "text"],
|
||||
["Greeter", "java.className"],
|
||||
[".", "java.operator"],
|
||||
["MAX", "java.staticSymbol"],
|
||||
["MAX", "java.staticFinalField"],
|
||||
],
|
||||
[[" }", "java.operator"]],
|
||||
[["}", "java.operator"]],
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
ATTRIBUTES,
|
||||
CLEAR_COLOR,
|
||||
SCHEMES,
|
||||
inheritChain,
|
||||
_setSchemeSource,
|
||||
overrideDeclarations,
|
||||
resolvedAttribute,
|
||||
@@ -65,6 +66,21 @@ describe("color schemes", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("resolves Java's Class Fields through the static and instance field defaults (#7643)", () => {
|
||||
const attr = (id: string) => ATTRIBUTES.find((a) => a.id === id)!;
|
||||
expect(inheritChain(attr("java.staticFinalField"))).toEqual(["java-constant", "static-property", "property"]);
|
||||
expect(inheritChain(attr("java.instanceFinalField"))).toEqual(["java-instance-final-field", "property"]);
|
||||
for (const scheme of ["dark", "light"]) {
|
||||
const field = resolvedAttribute(scheme, "field").foreground;
|
||||
expect(field).toBeTruthy();
|
||||
for (const id of ["java.staticFinalField", "java.staticField", "staticField"]) {
|
||||
expect(resolvedAttribute(scheme, id)).toMatchObject({ foreground: field, italic: true });
|
||||
}
|
||||
expect(resolvedAttribute(scheme, "java.instanceFinalField")).toMatchObject({ foreground: field });
|
||||
expect(resolvedAttribute(scheme, "java.instanceFinalField").italic).not.toBe(true);
|
||||
}
|
||||
});
|
||||
|
||||
it("keeps an imported scheme's gutter on its editor background unless it sets its own", () => {
|
||||
const customs = (gutter?: string) => ({
|
||||
"custom-a": {
|
||||
|
||||
@@ -355,6 +355,10 @@ const BASE_ATTRIBUTES: readonly AttributeDef[] = [
|
||||
syn("packageReference", "Identifiers › Package reference", [LD], "namespace"),
|
||||
syn("constant", "Identifiers › Constant", [LD], "constant", { defaultItalic: true }),
|
||||
syn("field", "Identifiers › Instance field", [LD], "property"),
|
||||
syn("staticField", "Identifiers › Static field", [LD], "static-property", {
|
||||
inherit: "property",
|
||||
defaultItalic: true,
|
||||
}),
|
||||
{
|
||||
id: "staticSymbol",
|
||||
name: "Identifiers › Static symbol",
|
||||
@@ -524,6 +528,18 @@ export const ATTRIBUTES: readonly AttributeDef[] = [
|
||||
...syn(`java.${id}`, name, ["Java"], token, { inherit: "type" }),
|
||||
language: "Java",
|
||||
})),
|
||||
// IntelliJ's Java › Class Fields: unset, each keeps the Language Defaults instance / static field style.
|
||||
...(
|
||||
[
|
||||
["instanceField", "Class Fields › Instance field", "java-instance-field", "property", false],
|
||||
["instanceFinalField", "Class Fields › Instance final field", "java-instance-final-field", "property", false],
|
||||
["staticField", "Class Fields › Static field", "java-static-field", "static-property", true],
|
||||
["staticFinalField", "Class Fields › Constant (static final field)", "java-constant", "static-property", true],
|
||||
] as const
|
||||
).map(([id, name, token, inherit, italic]) => ({
|
||||
...syn(`java.${id}`, name, ["Java"], token, { inherit, defaultItalic: italic }),
|
||||
language: "Java",
|
||||
})),
|
||||
// IntelliJ's Kotlin page: calls of top-level functions, and enum entries (IntelliJ falls back to
|
||||
// static method and static field, which are a function call and a constant here).
|
||||
...(
|
||||
@@ -936,6 +952,19 @@ const italicFromCss = (value: string | undefined): boolean | undefined => {
|
||||
return undefined;
|
||||
};
|
||||
|
||||
/**
|
||||
* An attribute's token, then the tokens it falls back to: its `inherit`, then that Language Defaults
|
||||
* attribute's own `inherit` (Java's Constant → Static field → Instance field).
|
||||
*/
|
||||
export function inheritChain(attr: AttributeDef): string[] {
|
||||
const chain = attr.token ? [attr.token] : [];
|
||||
for (let parent = attr.inherit; parent && !chain.includes(parent);) {
|
||||
chain.push(parent);
|
||||
parent = ATTRIBUTES.find((a) => a.token === parent && !a.language)?.inherit;
|
||||
}
|
||||
return chain;
|
||||
}
|
||||
|
||||
/**
|
||||
* The attributes an editor shows for a scheme before user overrides: imported
|
||||
* values where the scheme sets them, otherwise the theme token and the editor's
|
||||
@@ -969,9 +998,10 @@ export function resolvedAttribute(
|
||||
}
|
||||
|
||||
const token = attr.token;
|
||||
// An inheriting token's own value, else its parent's.
|
||||
// An inheriting token's own value, else its parent's, and so on up the chain.
|
||||
const chain = inheritChain(attr);
|
||||
const syn = (suffix: string) =>
|
||||
vars.get(`--syn-${token}${suffix}`) ?? (attr.inherit ? vars.get(`--syn-${attr.inherit}${suffix}`) : undefined);
|
||||
chain.map((t) => vars.get(`--syn-${t}${suffix}`)).find((value) => value !== undefined);
|
||||
const foreground = attr.fg ? (attr.inherit ? syn("") : vars.get(attr.fg)) : undefined;
|
||||
const background = attr.bg ? vars.get(attr.bg) : token ? syn("-bg") : undefined;
|
||||
const stripe = attr.stripe ? vars.get(attr.stripe) : undefined;
|
||||
|
||||
@@ -208,6 +208,27 @@ describe(".icls schemes", () => {
|
||||
expect(scheme.attributes["kotlin.enumEntry"]).toEqual({ foreground: "#c77dbb", bold: false, italic: true });
|
||||
});
|
||||
|
||||
it("imports IntelliJ's Java Class Fields and the default static field into their own entries (#7643)", () => {
|
||||
const opt = (name: string, value: string, font = "0") =>
|
||||
`<option name="${name}"><value><option name="FOREGROUND" value="${value}"/><option name="FONT_TYPE" value="${font}"/></value></option>`;
|
||||
const { scheme } = parseIcls(
|
||||
`<scheme name="J"><attributes>${opt("STATIC_FINAL_FIELD_ATTRIBUTES", "871094", "3")}${opt(
|
||||
"STATIC_FIELD_ATTRIBUTES",
|
||||
"871094",
|
||||
"2",
|
||||
)}${opt("INSTANCE_FINAL_FIELD_ATTRIBUTES", "871094", "1")}${opt("INSTANCE_FIELD_ATTRIBUTES", "871094")}${opt(
|
||||
"DEFAULT_STATIC_FIELD",
|
||||
"9876aa",
|
||||
"2",
|
||||
)}</attributes></scheme>`,
|
||||
);
|
||||
expect(scheme.attributes["java.staticFinalField"]).toEqual({ foreground: "#871094", bold: true, italic: true });
|
||||
expect(scheme.attributes["java.staticField"]).toEqual({ foreground: "#871094", bold: false, italic: true });
|
||||
expect(scheme.attributes["java.instanceFinalField"]).toEqual({ foreground: "#871094", bold: true, italic: false });
|
||||
expect(scheme.attributes["java.instanceField"]).toEqual({ foreground: "#871094", bold: false, italic: false });
|
||||
expect(scheme.attributes.staticField).toEqual({ foreground: "#9876aa", bold: false, italic: true });
|
||||
});
|
||||
|
||||
it("reads colours written with a leading # or 0x, as IntelliJ does (#5619)", () => {
|
||||
// One Dark writes most of its values as `#rrggbb`.
|
||||
const { scheme } = parseIcls(`<scheme name="One" parent_scheme="Darcula"><colors>
|
||||
|
||||
@@ -24,7 +24,7 @@ const ATTRIBUTE_NAMES: Record<string, string> = {
|
||||
DEFAULT_GLOBAL_VARIABLE: "globalVariable",
|
||||
DEFAULT_CONSTANT: "constant",
|
||||
DEFAULT_INSTANCE_FIELD: "field",
|
||||
DEFAULT_STATIC_FIELD: "constant",
|
||||
DEFAULT_STATIC_FIELD: "staticField",
|
||||
DEFAULT_FUNCTION_DECLARATION: "functionDeclaration",
|
||||
DEFAULT_FUNCTION_CALL: "functionCall",
|
||||
DEFAULT_PREDEFINED_SYMBOL: "predefined",
|
||||
@@ -138,6 +138,11 @@ Object.assign(ATTRIBUTE_NAMES, {
|
||||
KDOC_LINK: "kotlin.docCommentTagValue",
|
||||
CLASS_NAME_ATTRIBUTES: "className",
|
||||
...JAVA_TYPE_KEYS,
|
||||
// IntelliJ's Java › Class Fields.
|
||||
INSTANCE_FIELD_ATTRIBUTES: "java.instanceField",
|
||||
INSTANCE_FINAL_FIELD_ATTRIBUTES: "java.instanceFinalField",
|
||||
STATIC_FIELD_ATTRIBUTES: "java.staticField",
|
||||
STATIC_FINAL_FIELD_ATTRIBUTES: "java.staticFinalField",
|
||||
// IDEA DiffColors (Diff & Merge page): Import/export the four change types by their
|
||||
// exchange names, so a scheme exported here carries the same keys IDEA reads.
|
||||
DIFF_MODIFIED: "diffChanged",
|
||||
|
||||
@@ -1120,6 +1120,9 @@
|
||||
"Package reference": "Package reference",
|
||||
"Constant": "Constant",
|
||||
"Instance field": "Instance field",
|
||||
"Class Fields": "Class Fields",
|
||||
"Instance final field": "Instance final field",
|
||||
"Constant (static final field)": "Constant (static final field)",
|
||||
"Static symbol": "Static symbol",
|
||||
"Function declaration": "Function declaration",
|
||||
"Function call": "Function call",
|
||||
|
||||
@@ -939,6 +939,9 @@
|
||||
"Unindent on Backspace": "按退格键取消缩进",
|
||||
"Package reference": "包引用",
|
||||
"Instance field": "实例字段",
|
||||
"Class Fields": "类字段",
|
||||
"Instance final field": "实例 final 字段",
|
||||
"Constant (static final field)": "常量(static final 字段)",
|
||||
"Static symbol": "静态符号",
|
||||
"Function declaration": "函数声明",
|
||||
"Function call": "函数调用",
|
||||
|
||||
Reference in new issue
Заблокувати користувача