Файли
openidea/e2e/phpSemanticLocals.spec.ts
T
l0ng-ai 26688a79f7 feat(php): colour variables by name without server semantic tokens (#7905)
Semantic highlighting coloured locals only from server tokens, and Intelephense sends none, so PHP variables kept one colour with the option on. PHP now colours variables and parameters from the parse tree with the same name-to-colour rule; property declarations, static property access, $this and the superglobals are left out, and server tokens still win where they arrive.

Closes #7884
2026-12-04 09:27:27 +08:00

54 рядки
2.7 KiB
TypeScript

import type * as EditorBackend from "../src/editor/core/backend";
import { expect, test } from "./fixtures";
test("Semantic highlighting colours PHP variables by name without server tokens", async ({ workbench: page }, info) => {
await page.evaluate(async () => {
const projectPath = "/src/platform/project.ts";
const backendPath = "/src/editor/core/backend.ts";
const contributionsPath = "/src/workbench/contributions.ts";
const { useProject } = await import(projectPath);
const { docBackend }: typeof EditorBackend = await import(backendPath);
const { editorService } = await import(contributionsPath);
const previous = useProject.getState().settings ?? {};
useProject.setState({
settings: { ...previous, editor: { ...previous.editor, semanticHighlighting: true } },
});
const backend = docBackend();
if (!("files" in backend) || !(backend.files instanceof Map)) throw new Error("Expected the in-memory backend");
const open = backend.open.bind(backend);
backend.open = async (path) => {
const result = await open(path);
return path.endsWith(".php") ? { ...result, language: "php", uiMode: "PHP" } : result;
};
backend.files.set(
"/dev/acme-api/orders.php",
"<?php\nclass Orders {\n private $total = 0;\n\n function add(array $items, $discount) {\n foreach ($items as $item) {\n $price = $item['price'] - $discount;\n $this->total += $price;\n }\n return $this->total;\n }\n}\n",
);
await editorService().openFile("/dev/acme-api/orders.php");
});
const php = page.locator('.cm-editor[data-language="PHP"]');
await expect(php).toBeVisible();
const vars = (name: string) => php.locator(`.cm-content [class*="cm-sem-rainbow-"]`).filter({ hasText: name });
await expect(vars("$items")).toHaveCount(2);
await expect(vars("$discount")).toHaveCount(2);
await expect(vars("$price")).toHaveCount(2);
const colour = (name: string, nth = 0) =>
vars(name)
.nth(nth)
.evaluate((el) => getComputedStyle(el).color);
expect(await colour("$price", 0)).toBe(await colour("$price", 1));
expect(await colour("$items")).not.toBe(await colour("$discount"));
// Properties and $this stay as they are.
await expect(
php.locator('.cm-content [class*="cm-sem-rainbow-"]').filter({ hasText: /^\$(total|this)$/ }),
).toHaveCount(0);
const themePath = "/src/workbench/theme.ts";
for (const theme of ["light", "dark"] as const) {
await page.evaluate(async ({ path, t }) => (await import(/* @vite-ignore */ path)).setTheme(t), {
path: themePath,
t: theme,
});
await php.screenshot({ path: info.outputPath(`php-locals-${theme}.png`), animations: "disabled" });
}
});