提交 14bfbe5b 编写于 作者: M Manish Vasani

Merge pull request #5833 from mavasani/FixGetDiagnosticBySpan

Fix GetDiagnostics(span) to return all diagnostics intersecting the s…
......@@ -2148,7 +2148,7 @@ private static IEnumerable<Diagnostic> FilterDiagnosticsByLocation(IEnumerable<D
{
foreach (var diagnostic in diagnostics)
{
if (diagnostic.ContainsLocation(tree, filterSpanWithinTree))
if (diagnostic.HasIntersectingLocation(tree, filterSpanWithinTree))
{
yield return diagnostic;
}
......@@ -2179,7 +2179,7 @@ private static IEnumerable<Diagnostic> FilterDiagnosticsByLocation(IEnumerable<D
if (stage == CompilationStage.Declare || (stage > CompilationStage.Declare && includeEarlierStages))
{
var declarationDiagnostics = GetSourceDeclarationDiagnostics(syntaxTree, filterSpanWithinTree, FilterDiagnosticsByLocation, cancellationToken);
Debug.Assert(declarationDiagnostics.All(d => d.ContainsLocation(syntaxTree, filterSpanWithinTree)));
Debug.Assert(declarationDiagnostics.All(d => d.HasIntersectingLocation(syntaxTree, filterSpanWithinTree)));
builder.AddRange(declarationDiagnostics);
}
......
......@@ -81,9 +81,9 @@ class C : Abracadabra
DiagnosticsHelper.VerifyDiagnostics(model, source, @"(?s)^.*$", ErrorId);
DiagnosticsHelper.VerifyDiagnostics(model, source, @"Abracadabra", ErrorId);
DiagnosticsHelper.VerifyDiagnostics(model, source, @"C : Abracadabra", ErrorId);
DiagnosticsHelper.VerifyDiagnostics(model, source, @"C : Abracadabr");
DiagnosticsHelper.VerifyDiagnostics(model, source, @"C : Abracadabr", ErrorId);
DiagnosticsHelper.VerifyDiagnostics(model, source, @"Abracadabra[\r\n]+", ErrorId);
DiagnosticsHelper.VerifyDiagnostics(model, source, @"bracadabra[\r\n]+");
DiagnosticsHelper.VerifyDiagnostics(model, source, @"bracadabra[\r\n]+", ErrorId);
}
[Fact, WorkItem(1066483)]
......
......@@ -406,15 +406,15 @@ internal virtual IReadOnlyList<object> Arguments
}
/// <summary>
/// Returns true if the diagnostic location (or any additional location) is within the given tree and optional filterSpanWithinTree.
/// Returns true if the diagnostic location (or any additional location) is within the given tree and intersects with the filterSpanWithinTree, if non-null.
/// </summary>
internal bool ContainsLocation(SyntaxTree tree, TextSpan? filterSpanWithinTree = null)
internal bool HasIntersectingLocation(SyntaxTree tree, TextSpan? filterSpanWithinTree = null)
{
var locations = this.GetDiagnosticLocationsWithinTree(tree);
foreach (var location in locations)
{
if (!filterSpanWithinTree.HasValue || filterSpanWithinTree.Value.Contains(location.SourceSpan))
if (!filterSpanWithinTree.HasValue || filterSpanWithinTree.Value.IntersectsWith(location.SourceSpan))
{
return true;
}
......
......@@ -1981,7 +1981,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Private Shared Iterator Function FilterDiagnosticsByLocation(diagnostics As IEnumerable(Of Diagnostic), tree As SyntaxTree, filterSpanWithinTree As TextSpan?) As IEnumerable(Of Diagnostic)
For Each diagnostic In diagnostics
If diagnostic.ContainsLocation(tree, filterSpanWithinTree) Then
If diagnostic.HasIntersectingLocation(tree, filterSpanWithinTree) Then
Yield diagnostic
End If
Next
......
......@@ -29,7 +29,7 @@ End Class
DiagnosticsHelper.VerifyDiagnostics(model, sourceText, "(?s)^.*$", "BC30035", "BC30248", "BC30203", "BC30157")
DiagnosticsHelper.VerifyDiagnostics(model, sourceText, "@", "BC30035")
DiagnosticsHelper.VerifyDiagnostics(model, sourceText, "#", "BC30248")
DiagnosticsHelper.VerifyDiagnostics(model, sourceText, "(?<=\!)", "BC30203")
DiagnosticsHelper.VerifyDiagnostics(model, sourceText, "(?<=\!)", "BC30203", "BC30157")
DiagnosticsHelper.VerifyDiagnostics(model, sourceText, "!", "BC30203", "BC30157")
End Sub
......@@ -79,9 +79,9 @@ End Class
DiagnosticsHelper.VerifyDiagnostics(model, sourceText, "(?s)^.*$", ErrorId)
DiagnosticsHelper.VerifyDiagnostics(model, sourceText, "Abracadabra", ErrorId)
DiagnosticsHelper.VerifyDiagnostics(model, sourceText, "ts Abracadabra", ErrorId)
DiagnosticsHelper.VerifyDiagnostics(model, sourceText, "ts Abracadabr")
DiagnosticsHelper.VerifyDiagnostics(model, sourceText, "ts Abracadabr", ErrorId)
DiagnosticsHelper.VerifyDiagnostics(model, sourceText, "Abracadabra[\r\n]+", ErrorId)
DiagnosticsHelper.VerifyDiagnostics(model, sourceText, "bracadabra[\r\n]+")
DiagnosticsHelper.VerifyDiagnostics(model, sourceText, "bracadabra[\r\n]+", ErrorId)
End Sub
<Fact, WorkItem(1066483)>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册