diff --git a/src/platform/icls.test.ts b/src/platform/icls.test.ts
index 5f224ae88..cbd520414 100644
--- a/src/platform/icls.test.ts
+++ b/src/platform/icls.test.ts
@@ -712,3 +712,36 @@ describe(".icls schemes", () => {
}
});
});
+
+describe("annotation colour (#6108)", () => {
+ const opt = (name: string, value: string) =>
+ ``;
+ const scheme = (parent: string | null, ...options: string[]) =>
+ parseIcls(
+ `${options.join("")}`,
+ ).scheme;
+
+ it.each([
+ ["Default", "#808000"],
+ ["Darcula", "#bbb529"],
+ ])("keeps %s's own annotation colour when the file only changes DEFAULT_METADATA", (parent, colour) => {
+ // IntelliJ shows Java annotations with the parent's ANNOTATION_NAME_ATTRIBUTES, not the file's default.
+ expect(scheme(parent, opt("DEFAULT_METADATA", "1d8711")).attributes.metadata?.foreground).toBe(colour);
+ });
+
+ it("takes the file's annotation key over its DEFAULT_METADATA", () => {
+ const s = scheme("Default", opt("DEFAULT_METADATA", "1d8711"), opt("ANNOTATION_NAME_ATTRIBUTES", "9e880d"));
+ expect(s.attributes.metadata?.foreground).toBe("#9e880d");
+ });
+
+ it("uses DEFAULT_METADATA without a bundled parent", () => {
+ expect(scheme(null, opt("DEFAULT_METADATA", "1d8711")).attributes.metadata?.foreground).toBe("#1d8711");
+ });
+
+ it("exports the annotation colour under the annotation key, so it survives a re-import", () => {
+ const imported = scheme("Default", opt("ANNOTATION_NAME_ATTRIBUTES", "9e880d"));
+ const xml = exportIcls("custom-a", { "custom-a": imported });
+ expect(xml).toContain('
');
+ expect(parseIcls(xml).scheme.attributes.metadata?.foreground).toBe("#9e880d");
+ });
+});
diff --git a/src/platform/icls.ts b/src/platform/icls.ts
index 914066b0c..907185439 100644
--- a/src/platform/icls.ts
+++ b/src/platform/icls.ts
@@ -40,6 +40,8 @@ const ATTRIBUTE_NAMES: Record = {
DEFAULT_DOC_COMMENT_TAG: "docCommentTag",
DEFAULT_DOC_COMMENT_TAG_VALUE: "docCommentTagValue",
DEFAULT_DOC_MARKUP: "docCommentMarkup",
+ // Java's annotation key outranks the default it falls back to.
+ ANNOTATION_NAME_ATTRIBUTES: "metadata",
DEFAULT_METADATA: "metadata",
DEFAULT_OPERATION_SIGN: "operator",
DEFAULT_PARENTHS: "operator",
@@ -297,6 +299,8 @@ for (const id of [
// its fallback's. TypeScript keys win over JavaScript (TS.* falls back to JS.*), then Python, then the
// shared defaults; within a language, the key listed first above. DEFAULT_DOT, _COMMA and _SEMICOLON are
// not mapped: the one punctuation colour here would spread them to every brace and operator.
+/** ANNOTATION_NAME_ATTRIBUTES as IntelliJ's bundled Default and Darcula schemes set it. */
+const PARENT_ANNOTATIONS: Record = { Default: "#808000", Darcula: "#bbb529" };
const KEY_ORDER = new Map(Object.keys(ATTRIBUTE_NAMES).map((name, i) => [name, i]));
const LANGUAGE_PRECEDENCE = ["TS.", "JS.", "PY."];
const precedence = (name: string) => {
@@ -488,6 +492,10 @@ export function parseIcls(
const own = new Set([...entries.keys()].flatMap((name) => (name ? targets(name) : [])));
for (const [id, value] of Object.entries(DARCULA_ATTRIBUTES)) if (!own.has(id)) attributes[id] ??= { ...value };
}
+ // Both bundled parents set Java's annotation key itself, so a file that leaves it out shows the parent's
+ // colour there, not its own DEFAULT_METADATA.
+ if (Object.hasOwn(PARENT_ANNOTATIONS, parentName) && !entries.has("ANNOTATION_NAME_ATTRIBUTES"))
+ attributes.metadata = { bold: false, italic: false, foreground: PARENT_ANNOTATIONS[parentName]! };
const bg = attributes.text?.background;
const rgb = bg ? [1, 3, 5].map((i) => parseInt(bg.slice(i, i + 2), 16)) : [255, 255, 255];
const dark = rgb[0]! * 0.299 + rgb[1]! * 0.587 + rgb[2]! * 0.114 < 128;