From 58afe0b1547fe8f162f13bfb9ce4e34ded1853fc Mon Sep 17 00:00:00 2001 From: l0ng-ai <24760907+l0ng-ai@users.noreply.github.com> Date: Thu, 5 Nov 2026 23:07:38 +0800 Subject: [PATCH] fix(editor): colour PHP variables and function calls PHP editors showed $variables and function calls in the plain text colour, because the Language Defaults that PHP inherits leave both uncoloured. The built-in schemes now give PHP its own colours for them (PHP_VAR, PHP_FUNCTION_CALL): each scheme's instance-field purple and function blue. An imported scheme's PHP_VAR / PHP_FUNCTION_CALL and the user's PHP overrides still take precedence. --- src/platform/colorScheme.test.ts | 16 ++++++++++++++++ src/styles/tokens.css | 14 ++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/platform/colorScheme.test.ts b/src/platform/colorScheme.test.ts index 08e95786..b3766fe3 100644 --- a/src/platform/colorScheme.test.ts +++ b/src/platform/colorScheme.test.ts @@ -14,6 +14,22 @@ describe("color schemes", () => { expect(schemeTokens("light").get("--bg-editor")).not.toMatch(/var\(/); }); + it("gives PHP variables and function calls their own colours, as PhpStorm (#1532)", () => { + expect(schemeTokens("dark").get("--syn-php-variable")).toBe("#c77dbb"); + expect(schemeTokens("dark").get("--syn-php-function-call")).toBe("#56a8f5"); + expect(schemeTokens("light").get("--syn-php-variable")).toBe("#871094"); + expect(schemeTokens("light").get("--syn-php-function-call")).toBe("#00627a"); + const css = readFileSync("src/styles/tokens.css", "utf8"); + expect(css).toMatch(/\.cm-editor\[data-language="PHP"\] \{\s*--syn-variable: var\(--syn-php-variable\);/); + // An imported PHP_VAR still wins: language overrides are emitted for the same element, !important. + const imported = schemeCss( + "theme-default", + { dark: { "php.identifier": { foreground: "#48d8ee" } } }, + document.documentElement, + ); + expect(imported).toMatch(/\.cm-editor\[data-language="PHP"\] \{\n {2}--syn-variable: #48d8ee !important;/); + }); + it("emits scheme and override declarations", () => { const root = document.documentElement; root.dataset.theme = "light"; diff --git a/src/styles/tokens.css b/src/styles/tokens.css index 42822f63..a4d1f88a 100644 --- a/src/styles/tokens.css +++ b/src/styles/tokens.css @@ -132,6 +132,9 @@ html { --syn-python-constant: var(--syn-constant); --syn-python-property: var(--syn-property); --syn-python-type-parameter: var(--syn-type); + /* PhpStorm colours PHP variables and function calls on their own */ + --syn-php-variable: var(--syn-property); + --syn-php-function-call: var(--syn-function); --syn-builtin: #8888c6; --syn-self: #94558d; --syn-keyword-arg: #aa4926; @@ -523,6 +526,8 @@ html { --syn-python-constant: var(--syn-constant); --syn-python-property: var(--syn-property); --syn-python-type-parameter: var(--syn-type); + --syn-php-variable: var(--syn-property); + --syn-php-function-call: var(--syn-function); --syn-builtin: #000080; --syn-self: #94558d; --syn-keyword-arg: #660099; @@ -789,6 +794,8 @@ html { --syn-python-constant: var(--syn-constant); --syn-python-property: var(--syn-property); --syn-python-type-parameter: var(--syn-type); + --syn-php-variable: var(--syn-property); + --syn-php-function-call: var(--syn-function); --syn-builtin: #b0b0f0; --syn-self: #d08ac8; --syn-keyword-arg: #e0805c; @@ -1140,6 +1147,8 @@ html { --syn-python-constant: var(--syn-constant); --syn-python-property: var(--syn-property); --syn-python-type-parameter: var(--syn-type); + --syn-php-variable: var(--syn-property); + --syn-php-function-call: var(--syn-function); --syn-builtin: var(--palette-cyan); --syn-self: var(--palette-red); --syn-keyword-arg: var(--palette-red); @@ -1429,3 +1438,8 @@ html { --db-connected: var(--success); --db-connected-ring: var(--success); } +/* PHP editors: variables and function calls use the PHP colours (PHP_VAR / PHP_FUNCTION_CALL). */ +.cm-editor[data-language="PHP"] { + --syn-variable: var(--syn-php-variable); + --syn-function-call: var(--syn-php-function-call); +}