private void CreateErrors() { StaDynErrorList.Instance.refreshErrorList(); var errors = StaDynErrorList.Instance.GetErrors(); // remove any previously created errors to get a clean start ClearErrors(); foreach (ValidationError error in errors) { string currentPath = FileUtilities.Instance.getFilePath(textView); if (currentPath == error.File) { try { //ITrackingSpan span = textView.TextSnapshot.CreateTrackingSpan(error.Span, SpanTrackingMode.EdgeNegative); bool writeSquiggle = true; int startIndex = textView.TextBuffer.CurrentSnapshot.GetLineFromLineNumber(error.Line).Start.Position + error.Column; int endIndex = textView.TextBuffer.CurrentSnapshot.GetLineFromLineNumber(error.Line).Start.Position + error.Column + 4; SnapshotPoint point = new SnapshotPoint(textView.TextSnapshot, startIndex + 1); Span span = new Span(startIndex, endIndex - startIndex); ITrackingSpan trackingSpan = textView.TextSnapshot.CreateTrackingSpan(span, SpanTrackingMode.EdgeNegative); SnapshotSpan snapSpan = new SnapshotSpan(textView.TextSnapshot, span); var currentSquiggles = squiggleTagger.GetTaggedSpans(snapSpan); if (currentSquiggles.Count() == 0) { writeSquiggle = true; } else { foreach (var item in currentSquiggles) { if ((string)item.Tag.ToolTipContent == error.Description) { writeSquiggle = false; break; } } } if (writeSquiggle) { squiggleTagger.CreateTagSpan(trackingSpan, new ErrorTag("syntax error", error.Description)); previousSquiggles.Add(new TrackingTagSpan <IErrorTag>(trackingSpan, new ErrorTag("syntax error", error.Description))); } } catch { } } } }
// Re-collapse the spans public void CollapseRegions() { if (_outliningManager == null || _textView == null || _collapsedSpans == null) { return; } ITextSnapshot snapshot = _textView.TextBuffer.CurrentSnapshot; // Get a span that includes all collapsed regions int min = Int32.MinValue; int max = Int32.MinValue; foreach (Tuple <Span, IOutliningRegionTag> span in _collapsedSpans) { if (min == Int32.MinValue || span.Item1.Start < min) { min = span.Item1.Start; } if (max == Int32.MinValue || span.Item1.End > max) { max = span.Item1.End; } } // avoid running if there were no spans if (min == Int32.MinValue) { Debug.Fail("No spans"); return; } // span containing all collapsed regions SnapshotSpan entireSpan = new SnapshotSpan(snapshot, min, max - min); // regions have not yet been tagged by the language service during the undo/redo and // so we need to tag them again in order to do the collapse SimpleTagger <IOutliningRegionTag> simpleTagger = _textView.TextBuffer.Properties.GetOrCreateSingletonProperty <SimpleTagger <IOutliningRegionTag> >(() => new SimpleTagger <IOutliningRegionTag>(_textView.TextBuffer)); Debug.Assert(!simpleTagger.GetTaggedSpans(entireSpan).GetEnumerator().MoveNext(), "The code is not expecting the regions to be tagged already. Verify that redundant tagging is not occurring."); List <Span> toCollapse = new List <Span>(); // tag the regions and add them to the list to be bulk collapsed foreach (Tuple <Span, IOutliningRegionTag> span in _collapsedSpans) { ITrackingSpan tspan = snapshot.CreateTrackingSpan(span.Item1, SpanTrackingMode.EdgeExclusive); simpleTagger.CreateTagSpan(tspan, span.Item2); toCollapse.Add(span.Item1); } // Disable the OutliningUndoManager to avoid it adding our collapse to the undo stack as an expand bool disableOutliningUndo = _textView.Options.IsOutliningUndoEnabled(); try { if (disableOutliningUndo) { _textView.Options.SetOptionValue(DefaultTextViewOptions.OutliningUndoOptionId, false); } // Do the collapse _outliningManager.CollapseAll(entireSpan, colSpan => (!colSpan.IsCollapsed && toCollapse.Contains(colSpan.Extent.GetSpan(snapshot)))); } finally { if (disableOutliningUndo) { _textView.Options.SetOptionValue(DefaultTextViewOptions.OutliningUndoOptionId, true); } } }