PM: merge M2.2 deterministic highlighting tests
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
73819df926
1 changed files with 10 additions and 5 deletions
|
|
@ -4,7 +4,7 @@
|
||||||
* the spans CodeMirror draws for PHP, embedded HTML and the other
|
* the spans CodeMirror draws for PHP, embedded HTML and the other
|
||||||
* languages, each coloured by its `--lt-syntax-*` token.
|
* languages, each coloured by its `--lt-syntax-*` token.
|
||||||
*/
|
*/
|
||||||
import { ensureSyntaxTree } from "@codemirror/language";
|
import { forceParsing, syntaxTree } from "@codemirror/language";
|
||||||
import { EditorState } from "@codemirror/state";
|
import { EditorState } from "@codemirror/state";
|
||||||
import { EditorView } from "@codemirror/view";
|
import { EditorView } from "@codemirror/view";
|
||||||
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
||||||
|
|
@ -23,16 +23,21 @@ function stubRangeGeometry(): void {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shows a document in a view with the extensions of a file path, parsed
|
* Shows a document in a view with the extensions of a file path, parsed
|
||||||
* completely.
|
* completely before it returns. The parse is forced on the view itself:
|
||||||
|
* left alone, the view parses in time-budgeted slices, so under load the
|
||||||
|
* nested HTML layer of a PHP file could still be missing when a test reads
|
||||||
|
* the spans. Plain text has nothing to parse.
|
||||||
*
|
*
|
||||||
* @param path - the file path that picks the language.
|
* @param path - the file path that picks the language.
|
||||||
* @param doc - the text.
|
* @param doc - the text.
|
||||||
|
* @throws Error if the parse does not finish within a minute.
|
||||||
*/
|
*/
|
||||||
function show(path: string, doc: string): EditorView {
|
function show(path: string, doc: string): EditorView {
|
||||||
const state = EditorState.create({ doc, extensions: editorExtensions(path) });
|
const view = new EditorView({ state: EditorState.create({ doc, extensions: editorExtensions(path) }), parent: document.body });
|
||||||
ensureSyntaxTree(state, state.doc.length, 5000);
|
|
||||||
const view = new EditorView({ state, parent: document.body });
|
|
||||||
views.push(view);
|
views.push(view);
|
||||||
|
if (languageOf(path) !== null && (!forceParsing(view, doc.length, 60_000) || syntaxTree(view.state).length < doc.length)) {
|
||||||
|
throw new Error(`parse of ${path} did not finish`);
|
||||||
|
}
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue