diff --git a/src/EditorFeatures/Core/Implementation/Diagnostics/AbstractDiagnosticsTaggerProvider.cs b/src/EditorFeatures/Core/Implementation/Diagnostics/AbstractDiagnosticsTaggerProvider.cs index f13adc5e2ff046eb62cf5b924d206eb5f5084961..f4a4492c555db9511a3ff6fde12f6959f95f2c9f 100644 --- a/src/EditorFeatures/Core/Implementation/Diagnostics/AbstractDiagnosticsTaggerProvider.cs +++ b/src/EditorFeatures/Core/Implementation/Diagnostics/AbstractDiagnosticsTaggerProvider.cs @@ -97,15 +97,16 @@ private void ProduceTags(TaggerContext context, DocumentSnapshotSpan spanT foreach (var updateArg in eventArgs) { ProduceTags( - context, spanToTag, workspace, document, sourceText, editorSnapshot, + context, spanToTag, workspace, document, sourceText, suppressedDiagnosticsSpans, updateArg, cancellationToken); } } private void ProduceTags( TaggerContext context, DocumentSnapshotSpan spanToTag, - Workspace workspace, Document document, SourceText sourceText, ITextSnapshot editorSnapshot, - NormalizedSnapshotSpanCollection suppressedDiagnosticsSpans, UpdatedEventArgs updateArgs, CancellationToken cancellationToken) + Workspace workspace, Document document, SourceText sourceText, + NormalizedSnapshotSpanCollection suppressedDiagnosticsSpans, + UpdatedEventArgs updateArgs, CancellationToken cancellationToken) { try { @@ -116,7 +117,7 @@ private void ProduceTags(TaggerContext context, DocumentSnapshotSpan spanT var isLiveUpdate = id is ISupportLiveUpdate; var requestedSpan = spanToTag.SnapshotSpan; - var requestedSnapshot = requestedSpan.Snapshot; + var editorSnapshot = requestedSpan.Snapshot; foreach (var diagnosticData in diagnostics) { @@ -124,13 +125,14 @@ private void ProduceTags(TaggerContext context, DocumentSnapshotSpan spanT { // We're going to be retrieving the diagnostics against the last time the engine // computed them against this document *id*. That might have been a different - // version of the document vs what we're looking at now. As such, we have to - // ensure that the information we get back is not outside the bounds of the editor - // snapshot we're currently looking at. - - // Note: GetExistingOrCalculatedTextSpan always succeeds. But it does not ensure - // that the span it returns is within the span of sourceText. So we make sure that - // the start/end of it fits in our snapshot. + // version of the document vs what we're looking at now. But that's ok: + // + // 1) GetExistingOrCalculatedTextSpan will ensure that the diagnostics spans are + // contained within 'editorSnapshot'. + // 2) We'll eventually hear about an update to the diagnostics for this document + // for whatever edits happened between the last time and this current snapshot. + // So we'll eventually reach a point where the diagnostics exactly match the + // editorSnapshot. var diagnosticSpan = diagnosticData.GetExistingOrCalculatedTextSpan(sourceText) .ToSnapshotSpan(editorSnapshot);