/// <summary> /// Update the text lines of the document after a text change event. /// NOT thread-safe : this method can only be called from the owner thread. /// </summary> public void UpdateTextLines(TextChangedEvent textChangedEvent) { // This method can only be called by the document owner thread if (documentOwnerThread == null) { documentOwnerThread = Thread.CurrentThread; } else { VerifyAccess(); } // Make sure we don't update the document while taking a snapshot DocumentChangedEvent <ICobolTextLine> documentChangedEvent = null; lock (lockObjectForDocumentLines) { // Start perf measurement PerfStatsForText.OnStartRefresh(); // Apply text changes to the compilation document IList <DocumentChange <ICobolTextLine> > documentChanges = new List <DocumentChange <ICobolTextLine> >(textChangedEvent.TextChanges.Count); foreach (TextChange textChange in textChangedEvent.TextChanges) { DocumentChange <ICobolTextLine> appliedChange = null; CodeElementsLine newLine = null; bool encounteredCodeElement; switch (textChange.Type) { case TextChangeType.DocumentCleared: compilationDocumentLines.Clear(); appliedChange = new DocumentChange <ICobolTextLine>(DocumentChangeType.DocumentCleared, 0, null); // Ignore all previous document changes : they are meaningless now that the document was completely cleared documentChanges.Clear(); break; case TextChangeType.LineInserted: newLine = CreateNewDocumentLine(textChange.NewLine, TextSourceInfo.ColumnsLayout); compilationDocumentLines.Insert(textChange.LineIndex, newLine); encounteredCodeElement = false; //Will allow to update allow line index without erasing all diagnostics after the first encountered line with CodeElements foreach (var lineToUpdate in compilationDocumentLines.Skip(textChange.LineIndex + 1)) //Loop on every line that appears after added line { //Remove generated diagnostics for the line below the inserted line. if (!encounteredCodeElement) { lineToUpdate.ResetDiagnostics(); //Reset diag when on the same zone } lineToUpdate.LineIndex++; lineToUpdate.UpdateDiagnositcsLine(); if (lineToUpdate.CodeElements != null) { encounteredCodeElement = true; } } appliedChange = new DocumentChange <ICobolTextLine>(DocumentChangeType.LineInserted, textChange.LineIndex, newLine); break; case TextChangeType.LineUpdated: newLine = CreateNewDocumentLine(textChange.NewLine, TextSourceInfo.ColumnsLayout); compilationDocumentLines[textChange.LineIndex] = newLine; // Check to see if this change can be merged with a previous one bool changeAlreadyApplied = false; foreach (DocumentChange <ICobolTextLine> documentChangeToAdjust in documentChanges) { if (documentChangeToAdjust.LineIndex == textChange.LineIndex) { changeAlreadyApplied = true; break; } } if (!changeAlreadyApplied) { appliedChange = new DocumentChange <ICobolTextLine>(DocumentChangeType.LineUpdated, textChange.LineIndex, newLine); } // Line indexes are not impacted break; case TextChangeType.LineRemoved: compilationDocumentLines.RemoveAt(textChange.LineIndex); encounteredCodeElement = false; //Will allow to update allow line index without erasing all diagnostics after the first encountered line with CodeElements foreach (var lineToUpdate in compilationDocumentLines.Skip(textChange.LineIndex)) //Loop on every line that appears after deleted line { //Remove generated diagnostics for the line below the deleted line. if (!encounteredCodeElement) { lineToUpdate.ResetDiagnostics(); } lineToUpdate.LineIndex--; lineToUpdate.UpdateDiagnositcsLine(); if (lineToUpdate.CodeElements != null) { encounteredCodeElement = true; } } appliedChange = new DocumentChange <ICobolTextLine>(DocumentChangeType.LineRemoved, textChange.LineIndex, null); // Recompute the line indexes of all the changes prevously applied IList <DocumentChange <ICobolTextLine> > documentChangesToRemove = null; foreach (DocumentChange <ICobolTextLine> documentChangeToAdjust in documentChanges) { if (documentChangeToAdjust.LineIndex > textChange.LineIndex) { documentChangeToAdjust.LineIndex = documentChangeToAdjust.LineIndex - 1; } else if (documentChangeToAdjust.LineIndex == textChange.LineIndex) { if (documentChangesToRemove == null) { documentChangesToRemove = new List <DocumentChange <ICobolTextLine> >(1); } documentChangesToRemove.Add(documentChangeToAdjust); } } // Ignore all previous changes applied to a line now removed if (documentChangesToRemove != null) { foreach (DocumentChange <ICobolTextLine> documentChangeToRemove in documentChangesToRemove) { documentChanges.Remove(documentChangeToRemove); } } break; } if (appliedChange != null) { documentChanges.Add(appliedChange); } } // Create a new version of the document to track these changes currentTextLinesVersion.changes = documentChanges; currentTextLinesVersion.next = new DocumentVersion <ICobolTextLine>(currentTextLinesVersion); // Prepare an event to signal document change to all listeners documentChangedEvent = new DocumentChangedEvent <ICobolTextLine>(currentTextLinesVersion, currentTextLinesVersion.next); currentTextLinesVersion = currentTextLinesVersion.next; // Stop perf measurement PerfStatsForText.OnStopRefresh(); } // Send events to all listeners EventHandler <DocumentChangedEvent <ICobolTextLine> > textLinesChanged = TextLinesChanged; // avoid race condition if (textLinesChanged != null) { textLinesChanged(this, documentChangedEvent); } }
public IImmutableList <T> Clear() { _items = _items.Clear(); RaiseNotifyCollectionChanged(); return(this); }
protected override Task OnDispose() { documents = documents.Clear(); WatchDirectories(); return(base.OnDispose()); }
internal void Clear() { projects = projects.Clear(); RaiseOutputChanged(); }
public static ImmutableList <T> ResetContents <T>(this ImmutableList <T> list, IEnumerable <T> values) { return(list.SequenceEqual(values) ? list : list.Clear().AddRange(values)); }
internal void OnDrain() { //var log = LogManager.GetLogger(Global.CallerName()); //log.Info(string.Format("OnDrain1 PrevBufferLen={0} WriteBuffer.Count={1}", PrevBufferLen, WriteBuffer.Count)); for (int i = 0; i < this.PrevBufferLen; i++) { try { var callback = this.CallbackBuffer[i]; if (callback != null) { callback(); } } catch (ArgumentOutOfRangeException) { WriteBuffer = WriteBuffer.Clear(); CallbackBuffer = CallbackBuffer.Clear(); PrevBufferLen = 0; } } //log.Info(string.Format("OnDrain2 PrevBufferLen={0} WriteBuffer.Count={1}", PrevBufferLen, WriteBuffer.Count)); try { WriteBuffer = WriteBuffer.RemoveRange(0, PrevBufferLen); CallbackBuffer = CallbackBuffer.RemoveRange(0, PrevBufferLen); } catch (Exception) { WriteBuffer = WriteBuffer.Clear(); CallbackBuffer = CallbackBuffer.Clear(); } this.PrevBufferLen = 0; //log.Info(string.Format("OnDrain3 PrevBufferLen={0} WriteBuffer.Count={1}", PrevBufferLen, WriteBuffer.Count)); if (this.WriteBuffer.Count == 0) { this.Emit(EVENT_DRAIN); } else { this.Flush(); } }
public IImmutableList <T> Clear() { return(_list.Clear()); }
public void Clear() { OnNext(_Current.Clear()); OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); }
protected override ImmutableList <T> Clear(ImmutableList <T> values, ISerializationContext context) => values.Clear();
/// <summary> /// Removes all key-value pairs from this dictionary. /// </summary> public void Clear() { innerDictionary.Clear(); orderedKeyList.Clear(); }
public void Clear() { _listBuilder.Clear(); _dictionaryBuilder?.Clear(); }
public void Clear() { innerList = innerList.Clear(); }