/// <summary> /// Removes all tags associated with a given node /// </summary> /// <param name="node">Node in the AST</param> /// <returns>Text range that encloses removed tag spans</returns> public ITextRange RemoveTagsForNode(IAstNode node) { int start = _editorTree.TextBuffer().CurrentSnapshot.Length; ITextRange range = TextRange.EmptyRange; int end = 0; lock (_lockObj) { // Remove all tags for this node for (int i = 0; i < _tags.Count; i++) { if (TextRange.ContainsInclusiveEnd(node, _tags[i])) { start = Math.Min(start, _tags[i].Start); end = Math.Max(end, _tags[i].End); RemovedTags.Enqueue(_tags[i]); _tags.RemoveAt(i); i--; range = TextRange.Union(range, start, end - start); } } } return(range); }
private void ProcessPendingNodeRemoval() { int start = Int32.MaxValue; int end = 0; try { if (_nodesPendingRemoval.Count > 0) { lock (_lockObj) { IAstNode node; while (_nodesPendingRemoval.TryDequeue(out node)) { for (int j = 0; j < _tags.Count; j++) { if (TextRange.ContainsInclusiveEnd(node, _tags[j]) || node.Parent == null) { start = Math.Min(start, _tags[j].Start); end = Math.Max(end, _tags[j].End); RemovedTags.Enqueue(_tags[j]); _tags.RemoveAt(j); j--; } } } if (start != Int32.MaxValue) { if (_removedRange != null) { _removedRange = TextRange.Union(_removedRange, start, end - start); } else { _removedRange = TextRange.FromBounds(start, end); } } } } } finally { Interlocked.Exchange(ref _taskRunning, 0); } }