/// <summary> /// Builds initial AST. Subsequent updates should be coming from a background thread. /// </summary> public void Build() { if (_ownerThread != Thread.CurrentThread.ManagedThreadId) { throw new ThreadStateException("Method should only be called on the main thread"); } var sw = Stopwatch.StartNew(); TreeUpdateTask.Cancel(); if (TextBuffer != null) { TextSnapshot = TextBuffer.CurrentSnapshot; _astRoot = RParser.Parse(new TextProvider(TextBuffer.CurrentSnapshot)); } TreeUpdateTask.ClearChanges(); // Fire UpdatesPending notification, even though we don't have ranges for the event List <TextChangeEventArgs> textChanges = new List <TextChangeEventArgs>(); FireOnUpdatesPending(textChanges); FireOnUpdateBegin(); FireOnUpdateCompleted(TreeUpdateType.NewTree); sw.Stop(); }