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", "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" }); } });