mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-19 00:10:00 +00:00
Headless language tests could read an earlier, partial syntax tree after ensureSyntaxTree finished parsing, so highlight and state-based assertions depended on the initial 20 ms parse budget and failed intermittently under load. Shared test helpers now return the completed tree (or publish it to state), and every affected test uses them. Co-authored-by: arnaud-ritti <77437157+arnaud-ritti@users.noreply.github.com>
18 lines
783 B
TypeScript
18 lines
783 B
TypeScript
import { ensureSyntaxTree, language, syntaxTree } from "@codemirror/language";
|
|
import type { EditorState } from "@codemirror/state";
|
|
|
|
export function completedSyntaxTree(state: EditorState, timeout = 1000) {
|
|
const tree = ensureSyntaxTree(state, state.doc.length, timeout);
|
|
if (!tree) throw new Error("Test syntax parsing did not finish");
|
|
return tree;
|
|
}
|
|
|
|
export function completedSyntaxState(state: EditorState, timeout = 5000) {
|
|
if (!state.facet(language)) return state;
|
|
const tree = completedSyntaxTree(state, timeout);
|
|
// A transaction snapshots the completed parse context into the immutable state.
|
|
const parsed = state.update({}).state;
|
|
if (syntaxTree(parsed) !== tree) throw new Error("Test state did not publish the completed syntax tree");
|
|
return parsed;
|
|
}
|