Skip to content

The IDE you know, rebuilt in Rust. IntelliJ IDEA–style keymap, tool windows and search-everywhere in a fast native app: editor, code insight, debugger, Git, terminal, database and HTTP clients for 60+ languages.

783 B
Raw Blame
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;
}