KhaosCoders / VSCodeBlockEndTag

A VisualStudio 2017, 2019 and 2022 extension. It adds an end tag to each code block with information about the header / condition
https://khaos-coders.org/projects/visual-studio/codeblockendtag
GNU General Public License v3.0
20 stars 9 forks source link

Exceptions when working with VS2015 update 3 #1

Closed wmjordan closed 7 years ago

wmjordan commented 8 years ago

It threw exceptions when I was working in VS 2015 update 3. The stack trace was:

System.ArgumentOutOfRangeException: Microsoft.VisualStudio.Text.SnapshotSpan..ctor(ITextSnapshot snapshot, Span span)
CodeBlockEndTag.CBETagger.InvalidateSpan(Span invalidateSpan, Boolean clearCache)
CodeBlockEndTag.CBETagger.OnTextViewLayoutChanged(Object sender, TextViewLayoutChangedEventArgs e)
Microsoft.VisualStudio.Text.Utilities.GuardedOperations.RaiseEvent[TArgs](Object sender, EventHandler`1 eventHandlers, TArgs args)
wmjordan commented 7 years ago

It appeared that I'd fixed this issue. Please change the last two lines of the InvalidateSpan method in CBETagger.cs to the following lines. By checking the End of the span and the Length of the snapshot, the problem was gone.

if (invalidateSpan.End <= _TextView.TextBuffer.CurrentSnapshot.Length) {
    _changedEvent?.Invoke(this, new SnapshotSpanEventArgs(
        new SnapshotSpan(_TextView.TextBuffer.CurrentSnapshot, invalidateSpan)));
}
Khaos66 commented 7 years ago

Thank you!