public IEnumerable <ITagSpan <ClassificationTag> > GetTags(Microsoft.VisualStudio.Text.NormalizedSnapshotSpanCollection spans) { if (activeSpans == null) { yield break; } if (activeSpans.Count == 0 || spans.Count == 0) { yield break; } if (activeSpans[0].Snapshot != spans[0].Snapshot) { activeSpans = new NormalizedSnapshotSpanCollection( activeSpans.Select( span => span.TranslateTo(spans[0].Snapshot, SpanTrackingMode.EdgeExclusive) )); } foreach (var span in NormalizedSnapshotSpanCollection.Overlap(spans, activeSpans)) { yield return(new TagSpan <ClassificationTag>(span, new ClassificationTag(ClassificationType))); } }
/// <summary> /// Gets a list of tags related to a span /// </summary> /// <param name="spans"></param> /// <returns></returns> public IEnumerable <ITagSpan <ErrorTag> > GetTags(Microsoft.VisualStudio.Text.NormalizedSnapshotSpanCollection spans) { foreach (SnapshotSpan span in spans) { foreach (DesignerNode node in nodeProvider.GetNodes(span, node => node.NodeType != NDjango.Interfaces.NodeType.ParsingContext)) { switch (node.ErrorMessage.Severity) { case -1: case 0: continue; case 1: yield return(new TagSpan <ErrorTag>(node.SnapshotSpan, new ErrorTag(PredefinedErrorTypeNames.Warning))); break; default: yield return(new TagSpan <ErrorTag>(node.SnapshotSpan, new ErrorTag(PredefinedErrorTypeNames.SyntaxError))); break; } } } }
public IEnumerable <ITagSpan <TodoGlyphTag> > GetTags(Microsoft.VisualStudio.Text.NormalizedSnapshotSpanCollection spans) { foreach (var span in spans) { String text = span.GetText(); var match = todoLineRegex.Match(text); if (match.Success) { var point = span.Start.Add(match.Index); var spanNew = new SnapshotSpan(span.Snapshot, new Span(point.Position, match.Length)); var hasDueBy = false; if (match.Groups.Count == 2 && match.Groups[1].Value.ToLower() == "by") { hasDueBy = true; } ITextViewLine line = null; DateTime? dueDate = null; string friendly = null; try { line = _textView.Caret.ContainingTextViewLine; if (hasDueBy) { var dateSpan = new SnapshotSpan(span.Snapshot, new Span(point.Position + match.Length, span.Length - match.Length)); var str = dateSpan.GetText(); DateMatcher matcher = new DateMatcher(); dueDate = matcher.FromString(str, out friendly); // Bail if there isn't a good date found (should give visual feedback to dev). if (!dueDate.HasValue) { continue; } } } catch (Exception ex) { continue; } var actions = new ReadOnlyCollection <SmartTagActionSet>(new SmartTagActionSet[] {}.ToList()); if (line != null && //_textView.Caret.ContainingTextViewLine.ContainsBufferPosition(span.Start) //true _textView.TextSnapshot.GetLineNumberFromPosition(_textView.Caret.Position.BufferPosition) == span.Start.GetContainingLine().LineNumber ) { actions = GetSmartTagActions(spanNew, dueDate, friendly); } yield return(new TagSpan <TodoGlyphTag>(spanNew, new TodoGlyphTag(SmartTagType.Ephemeral, actions) )); } } }
/// <summary> /// Gets a list of tags related to a span /// </summary> /// <param name="spans"></param> /// <returns></returns> public IEnumerable <ITagSpan <Constants.ErrorTag> > GetTags(Microsoft.VisualStudio.Text.NormalizedSnapshotSpanCollection spans) { foreach (SnapshotSpan span in spans) { foreach (DesignerNode node in nodeProvider.GetNodes(span, node => node.NodeType != NDjango.Interfaces.NodeType.ParsingContext)) { if (node.ErrorMessage.Severity > -1) { yield return(new TagSpan <Constants.ErrorTag>(node.SnapshotSpan, new Constants.ErrorTag())); } } } }
/// <summary> /// Computes the difference between two normalized snapshot span collections and normalizes the result. /// </summary> /// <param name="left">The collection from which to subtract <paramref name="right"/>.</param> /// <param name="right">The collection to subtract from <paramref name="left"/>.</param> /// <returns>The normalized set difference.</returns> /// <exception cref="ArgumentNullException"><paramref name="left"/> or <paramref name="right"/> is null.</exception> /// <exception cref="ArgumentException">The input collections refer to different snapshots.</exception> public static NormalizedSnapshotSpanCollection Difference(NormalizedSnapshotSpanCollection left, NormalizedSnapshotSpanCollection right) { if (left == null) { throw new ArgumentNullException("left"); } if (right == null) { throw new ArgumentNullException("right"); } if (left.Count == 0) { return(left); } if (right.Count == 0) { return(left); } if (left.snapshot != right.snapshot) { throw new ArgumentException(Strings.MismatchedSnapshots); } NormalizedSpanCollection leftSpans = left.spans ?? new NormalizedSpanCollection(left.span); NormalizedSpanCollection rightSpans = right.spans ?? new NormalizedSpanCollection(right.span); return(new NormalizedSnapshotSpanCollection(left[0].Snapshot, NormalizedSpanCollection.Difference(leftSpans, rightSpans))); }
/// <summary> /// Determines whether two snapshot span collections are equal /// </summary> /// <param name="obj">The second collection.</param> /// <returns><c>true</c> if the two collections are equal, otherwise <c>false</c>.</returns> public override bool Equals(object obj) { NormalizedSnapshotSpanCollection set = obj as NormalizedSnapshotSpanCollection; return(this == set); }