/// <summary>Gets a sorted array which contains parsed tags.</summary> public TaggedContentSpan[] GetTags() { var tags = _Tags; var r = new TaggedContentSpan[tags.Count]; tags.CopyTo(r); Array.Sort(r, (x, y) => x.Start - y.Start); return(r); }
public TaggedContentSpan GetPreceedingTaggedSpan(int position) { var tags = _Tags; TaggedContentSpan t = null; for (int i = tags.Count - 1; i >= 0; i--) { var tag = tags[i]; if (tag.Contains(position)) { return(tag); } if (position > tag.Start && (t == null || tag.Start > t.Start)) { t = tag; } } return(t); }
public TaggedContentSpan Add(TaggedContentSpan tag) { var s = tag.Span; if (s.Start < Start) { Start = s.Start; } var tags = _Tags; for (int i = tags.Count - 1; i >= 0; i--) { if (tags[i].Contains(s.Start)) { return(tags[i] = tag); } } tags.Add(tag); return(tag); }
public IEnumerable <ITagSpan <IClassificationTag> > GetTags(NormalizedSnapshotSpanCollection spans) { if (spans.Count == 0 || Config.Instance.SpecialHighlightOptions.MatchFlags(SpecialHighlightOptions.SpecialComment) == false) { yield break; } var snapshot = spans[0].Snapshot; IEnumerable <IMappingTagSpan <IClassificationTag> > tagSpans; try { if (_Tags.LastParsed == 0) { // perform a full parse for the first time Debug.WriteLine("Full parse"); tagSpans = _Aggregator.GetTags(new SnapshotSpan(snapshot, 0, snapshot.Length)); _Tags.LastParsed = snapshot.Length; } else { //var start = spans[0].Start; //var end = spans[spans.Count - 1].End; //Debug.WriteLine($"Get tag [{start.Position}..{end.Position})"); tagSpans = _Aggregator.GetTags(spans); } } catch (ObjectDisposedException ex) { // HACK: TagAggregator could be disposed during editing, to be investigated further Debug.WriteLine(ex.Message); yield break; } TaggedContentSpan ts, s = null; foreach (var tagSpan in tagSpans) { #if DEBUG var c = tagSpan.Tag.ClassificationType.Classification; if (_ClassificationTypes.Add(c)) { Debug.WriteLine("Classification type: " + c); } #endif ts = TagComments(tagSpan.Span.GetSpans(snapshot)[0], tagSpan); if (ts != null) { if (s == null) { s = ts; } yield return(_Tags.Add(ts)); } } if (s != null) { TagAdded?.Invoke(this, EventArgs.Empty); // note: Don't use the TagsChanged event, otherwise infinite loops will occur //TagsChanged?.Invoke(this, new SnapshotSpanEventArgs(s.Span)); } }