From 8aeac949b512f5073b6a0435be4b0888c76dfcfe Mon Sep 17 00:00:00 2001 From: zhzhsx Date: Sat, 28 Nov 2026 20:09:09 +0800 Subject: [PATCH] fix(editor): map t.namespace to Package reference, not Class name (#6684) Syntax highlighting coloured t.namespace with Class name while semantic highlighting used Package reference, so namespace identifiers changed colour once the language server's tokens arrived. t.namespace now uses the namespace scheme attribute and falls back to Class name when a scheme leaves it unset. Co-authored-by: zhzhsx <1379025+zhzhsx@users.noreply.github.com> --- src/editor/core/cm/highlight.ts | 4 +++- src/editor/core/cm/syntaxHighlight.test.ts | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/editor/core/cm/highlight.ts b/src/editor/core/cm/highlight.ts index e9be93e554..757c407aa4 100644 --- a/src/editor/core/cm/highlight.ts +++ b/src/editor/core/cm/highlight.ts @@ -53,7 +53,9 @@ export const openideaHighlightStyle = HighlightStyle.define([ token(t.escape, "escape"), token(t.regexp, "regexp"), token([t.number, t.integer, t.float], "number"), - token([t.typeName, t.className, t.namespace, t.definition(t.typeName)], "type"), + token([t.typeName, t.className, t.definition(t.typeName)], "type"), + // Package references get their own scheme attribute (IDEA's Package reference), with Class name as fallback. + token(t.namespace, "namespace", { color: "type" }), token(t.standard(t.variableName), "builtin"), token(t.standard(t.typeName), "builtin-type", { color: "builtin" }), token(t.standard(t.function(t.variableName)), "builtin-function", { color: "builtin" }), diff --git a/src/editor/core/cm/syntaxHighlight.test.ts b/src/editor/core/cm/syntaxHighlight.test.ts index 0ea2e3f475..b1f0033291 100644 --- a/src/editor/core/cm/syntaxHighlight.test.ts +++ b/src/editor/core/cm/syntaxHighlight.test.ts @@ -54,6 +54,13 @@ describe("syntaxHighlightField", () => { expect(marks(state)).toEqual([{ text: "def", cls: command }]); }); + it("maps t.namespace to Package reference, not Class name", () => { + const namespaceClass = openideaHighlightStyle.style([t.namespace]); + const typeClass = openideaHighlightStyle.style([t.typeName]); + expect(namespaceClass).toBeTruthy(); + expect(namespaceClass).not.toBe(typeClass); + }); + it("lets Kotlin declaration roles override the stream lexer's generic definition style", async () => { const support = await loadSupport(findLanguageDescription("Kotlin", "demo.kt")!); const view = new EditorView({