private void OnDocumentParseComplete(DocumentParseCompleteEventArgs args) { Debug.Assert(args != null, "Event arguments cannot be null"); EventHandler <DocumentParseCompleteEventArgs> handler = DocumentParseComplete; if (handler != null) { handler(this, args); } #if DEBUG RazorDebugHelpers.WriteDebugTree(FileName, args.GeneratorResults.Document, PartialParseResult.Rejected, args.SourceChange, this, args.TreeStructureChanged); RazorDebugHelpers.WriteGeneratedCode(FileName, args.GeneratorResults.GeneratedCode); #endif }
/// <summary> /// Determines if a change will cause a structural change to the document and if not, applies it to the existing tree. /// If a structural change would occur, automatically starts a reparse /// </summary> /// <remarks> /// NOTE: The initial incremental parsing check and actual incremental parsing (if possible) occurs /// on the callers thread. However, if a full reparse is needed, this occurs on a background thread. /// </remarks> /// <param name="change">The change to apply to the parse tree</param> /// <returns>A PartialParseResult value indicating the result of the incremental parse</returns> public virtual PartialParseResult CheckForStructureChanges(TextChange change) { // Validate the change if (change.NewBuffer == null) { throw new ArgumentException(String.Format(CultureInfo.CurrentUICulture, RazorResources.Structure_Member_CannotBeNull, "Buffer", "TextChange"), "change"); } PartialParseResult result = PartialParseResult.Rejected; // Lock the state objects lock (_lock) { // If there isn't already a parse underway, try partial-parsing if (CurrentParseTree != null && _outstandingParserTasks.Count == 0) { result = TryPartialParse(change); } // If partial parsing failed or there were outstanding parser tasks, start a full reparse if (result.HasFlag(PartialParseResult.Rejected)) { QueueFullReparse(change); } #if DEBUG else { if (CurrentParseTree != null) { RazorDebugHelpers.WriteDebugTree(FileName, CurrentParseTree, result, change, this, false); } if (_currentCompileUnit != null) { RazorDebugHelpers.WriteGeneratedCode(FileName, _currentCompileUnit); } } #endif // Otherwise, remember if this was provisionally accepted for next partial parse LastResultProvisional = result.HasFlag(PartialParseResult.Provisional); } VerifyFlagsAreValid(result); return(result); }
/// <summary> /// Determines if a change will cause a structural change to the document and if not, applies it to the existing tree. /// If a structural change would occur, automatically starts a reparse /// </summary> /// <remarks> /// NOTE: The initial incremental parsing check and actual incremental parsing (if possible) occurs /// on the callers thread. However, if a full reparse is needed, this occurs on a background thread. /// </remarks> /// <param name="change">The change to apply to the parse tree</param> /// <returns>A PartialParseResult value indicating the result of the incremental parse</returns> public virtual PartialParseResult CheckForStructureChanges(TextChange change) { // Validate the change if (change.NewBuffer == null) { throw new ArgumentException(String.Format(CultureInfo.CurrentUICulture, RazorResources.Structure_Member_CannotBeNull, "Buffer", "TextChange"), "change"); } // Acquire the sync lock (we need to be fast now, since we're on the UI thread) PartialParseResult result = PartialParseResult.Rejected; bool lockTaken = false; try { _syncLock.Enter(ref lockTaken); if (lockTaken) { if (!_parseUnderway) { result = TryPartialParse(change); } // Provisional Acceptance means we accept it, but set a flag indicating that we should force // a reparse if the next change is not accepted by the same span that accepted this change. // Rejected or Accepted means we clear the LastResultProvisional flag LastResultProvisional = result.HasFlag(PartialParseResult.Provisional); if (result.HasFlag(PartialParseResult.Rejected)) { _parseUnderway = true; // Queue a reparse to occur on a _background_ thread QueueFullReparse(change); } #if DEBUG else { if (_currentParseTree != null) { RazorDebugHelpers.WriteDebugTree(_sourceFileName, _currentParseTree, result, change, this, false); } if (_currentCodeCompileUnit != null) { RazorDebugHelpers.WriteGeneratedCode(_sourceFileName, _currentCodeCompileUnit); } } #endif } } finally { if (_syncLock.IsHeldByCurrentThread) { _syncLock.Exit(); } } VerifyFlagsAreValid(result); return(result); }