import { afterEach, describe, expect, it } from "vitest"; import { EditorState } from "@codemirror/state"; import { EditorView } from "@codemirror/view"; import { languages } from "@codemirror/language-data"; import { phpConstructAt, phpConstructDocumentation } from "./phpConstructs"; import { lspDoc } from "./lsp"; import { quickDefinition, requestHover } from "./hover"; import { gotoTargets } from "./navigation"; import { closePopup, useLspPopup } from "./popupStore"; const php = await languages.find((l) => l.name === "PHP")!.load(); const views: EditorView[] = []; afterEach(() => { closePopup(); for (const view of views.splice(0)) view.destroy(); }); function state(doc: string) { return EditorState.create({ doc, extensions: [php] }); } describe("PHP language constructs", () => { it.each(["empty", "isset", "EMPTY"])("documents %s at either edge of its name", (name) => { const s = state(`empty();", "empty();", "empty($x)

{ const s = state(text); for (const match of text.matchAll(/empty/g)) expect(phpConstructAt(s, match.index + 2, "php")).toBeNull(); }); it("does not attach PHP docs to other languages or ordinary functions", () => { expect(phpConstructAt(state(" { const view = new EditorView({ state: EditorState.create({ doc: " gotoTargets(view, "definition"), () => gotoTargets(view, "declaration"), () => quickDefinition(view), ]) { await action(); const popup = useLspPopup.getState().popup; expect(popup?.kind).toBe("doc"); if (popup?.kind === "doc") expect(popup.entries[0]?.markup.value).toContain("no source declaration"); closePopup(); } }); });