Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline Diagnostics Multi-Line Errors #60013

Merged
merged 1 commit into from
Mar 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ protected bool ShouldDrawTag(SnapshotSpan snapshotSpan, IMappingTagSpan<T> mappi

protected SnapshotPoint? GetMappedPoint(SnapshotSpan snapshotSpan, IMappingTagSpan<T> mappingTagSpan)
{
var point = mappingTagSpan.Span.Start.GetPoint(snapshotSpan.Snapshot, PositionAffinity.Predecessor);
var point = mappingTagSpan.Span.End.GetPoint(snapshotSpan.Snapshot, PositionAffinity.Predecessor);
if (point == null)
{
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,47 +116,6 @@ private TextFormattingRunProperties GetFormat(IClassificationType classification
return _formatMap.GetTextProperties(classificationType);
}

/// <summary>
/// Get the spans located on each line so that it can only display the first one that appears on the line
/// </summary>
private void AddSpansOnEachLine(NormalizedSnapshotSpanCollection changedSpanCollection,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change just moving the method? Can you undo if that's the only change to this file?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I just moved the method since it should've been below the calling method. Do I need to create a separate PR for that?

Dictionary<int, IMappingTagSpan<InlineDiagnosticsTag>> map)
{
var viewLines = TextView.TextViewLines;

foreach (var changedSpan in changedSpanCollection)
{
if (!viewLines.IntersectsBufferSpan(changedSpan))
{
continue;
}

var tagSpans = TagAggregator.GetTags(changedSpan);
foreach (var tagMappingSpan in tagSpans)
{
if (!ShouldDrawTag(changedSpan, tagMappingSpan, out var mappedPoint))
{
continue;
}

// mappedPoint is known to not be null here because it is checked in the ShouldDrawTag method call.
var lineNum = mappedPoint.GetContainingLine().LineNumber;

// If the line does not have an associated tagMappingSpan and changedSpan, then add the first one.
if (!map.TryGetValue(lineNum, out var value))
{
map.Add(lineNum, tagMappingSpan);
}
else if (value.Tag.ErrorType is not PredefinedErrorTypeNames.SyntaxError && tagMappingSpan.Tag.ErrorType is PredefinedErrorTypeNames.SyntaxError)
{
// Draw the first instance of an error, if what is stored in the map at a specific line is
// not an error, then replace it. Otherwise, just get the first warning on the line.
map[lineNum] = tagMappingSpan;
}
}
}
}

/// <summary>
/// Iterates through the mapping of line number to span and draws the diagnostic in the appropriate position on the screen,
/// as well as adding the tag to the adornment layer.
Expand Down Expand Up @@ -238,5 +197,46 @@ protected override void AddAdornmentsToAdornmentLayer_CallOnlyOnUIThread(Normali
removedCallback: delegate { graphicsResult.Dispose(); });
}
}

/// <summary>
/// Get the spans located on each line so that it can only display the first one that appears on the line
/// </summary>
private void AddSpansOnEachLine(NormalizedSnapshotSpanCollection changedSpanCollection,
Dictionary<int, IMappingTagSpan<InlineDiagnosticsTag>> map)
{
var viewLines = TextView.TextViewLines;

foreach (var changedSpan in changedSpanCollection)
{
if (!viewLines.IntersectsBufferSpan(changedSpan))
{
continue;
}

var tagSpans = TagAggregator.GetTags(changedSpan);
foreach (var tagMappingSpan in tagSpans)
{
if (!ShouldDrawTag(changedSpan, tagMappingSpan, out var mappedPoint))
{
continue;
}

// mappedPoint is known to not be null here because it is checked in the ShouldDrawTag method call.
var lineNum = mappedPoint.GetContainingLine().LineNumber;

// If the line does not have an associated tagMappingSpan and changedSpan, then add the first one.
if (!map.TryGetValue(lineNum, out var value))
{
map.Add(lineNum, tagMappingSpan);
}
else if (value.Tag.ErrorType is not PredefinedErrorTypeNames.SyntaxError && tagMappingSpan.Tag.ErrorType is PredefinedErrorTypeNames.SyntaxError)
{
// Draw the first instance of an error, if what is stored in the map at a specific line is
// not an error, then replace it. Otherwise, just get the first warning on the line.
map[lineNum] = tagMappingSpan;
}
}
}
}
}
}