未验证 提交 8362bde5 编写于 作者: A AlekseyTs 提交者: GitHub

Respect filterTree and filterSpanWithinTree while collecting diagnostics for...

Respect filterTree and filterSpanWithinTree while collecting diagnostics for misplaced doc comments. (#39525)

Fixes #39315.
上级 9806069c
......@@ -3167,6 +3167,106 @@ public void TestXmlPermissionElement()
Assert.Equal<string>(expected, actual);
}
[Fact]
[WorkItem(39315, "https://github.com/dotnet/roslyn/issues/39315")]
public void WriteDocumentationCommentXml_01()
{
var comp = CreateCompilation(new[] {
Parse(@"
/// <summary> a
/// </summary>
"),
Parse(@"
/// <summary> b
/// </summary>
")});
var diags = DiagnosticBag.GetInstance();
DocumentationCommentCompiler.WriteDocumentationCommentXml(
comp,
assemblyName: null,
xmlDocStream: null,
diags,
default(CancellationToken),
filterTree: comp.SyntaxTrees[0]);
diags.ToReadOnlyAndFree().Verify(
// (2,1): warning CS1587: XML comment is not placed on a valid language element
// /// <summary> a
Diagnostic(ErrorCode.WRN_UnprocessedXMLComment, "/").WithLocation(2, 1)
);
diags = DiagnosticBag.GetInstance();
DocumentationCommentCompiler.WriteDocumentationCommentXml(
comp,
assemblyName: null,
xmlDocStream: null,
diags,
default(CancellationToken),
filterTree: comp.SyntaxTrees[0],
filterSpanWithinTree: new TextSpan(0, 0));
diags.ToReadOnlyAndFree().Verify();
diags = DiagnosticBag.GetInstance();
DocumentationCommentCompiler.WriteDocumentationCommentXml(
comp,
assemblyName: null,
xmlDocStream: null,
diags,
default(CancellationToken),
filterTree: comp.SyntaxTrees[1]);
diags.ToReadOnlyAndFree().Verify(
// (3,1): warning CS1587: XML comment is not placed on a valid language element
// /// <summary> b
Diagnostic(ErrorCode.WRN_UnprocessedXMLComment, "/").WithLocation(3, 1)
);
diags = DiagnosticBag.GetInstance();
DocumentationCommentCompiler.WriteDocumentationCommentXml(
comp,
assemblyName: null,
xmlDocStream: null,
diags,
default(CancellationToken),
filterTree: null);
diags.ToReadOnlyAndFree().Verify(
// (2,1): warning CS1587: XML comment is not placed on a valid language element
// /// <summary> a
Diagnostic(ErrorCode.WRN_UnprocessedXMLComment, "/").WithLocation(2, 1),
// (3,1): warning CS1587: XML comment is not placed on a valid language element
// /// <summary> b
Diagnostic(ErrorCode.WRN_UnprocessedXMLComment, "/").WithLocation(3, 1)
);
diags = DiagnosticBag.GetInstance();
DocumentationCommentCompiler.WriteDocumentationCommentXml(
comp,
assemblyName: null,
xmlDocStream: null,
diags,
default(CancellationToken),
filterTree: null,
filterSpanWithinTree: new TextSpan(0, 0));
diags.ToReadOnlyAndFree().Verify(
// (2,1): warning CS1587: XML comment is not placed on a valid language element
// /// <summary> a
Diagnostic(ErrorCode.WRN_UnprocessedXMLComment, "/").WithLocation(2, 1),
// (3,1): warning CS1587: XML comment is not placed on a valid language element
// /// <summary> b
Diagnostic(ErrorCode.WRN_UnprocessedXMLComment, "/").WithLocation(3, 1)
);
}
#region Xml Test helpers
/// <summary>
......
......@@ -83,9 +83,13 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
diagnostics.Add(ERRID.ERR_DocFileGen, Location.None, ex.Message)
End Try
For Each tree In compilation.SyntaxTrees
MislocatedDocumentationCommentFinder.ReportUnprocessed(tree, filterSpanWithinTree, diagnostics, cancellationToken)
Next
If filterTree IsNot Nothing Then
MislocatedDocumentationCommentFinder.ReportUnprocessed(filterTree, filterSpanWithinTree, diagnostics, cancellationToken)
Else
For Each tree In compilation.SyntaxTrees
MislocatedDocumentationCommentFinder.ReportUnprocessed(tree, filterSpanWithinTree:=Nothing, diagnostics, cancellationToken)
Next
End If
End Sub
Private ReadOnly Property [Module] As SourceModuleSymbol
......
......@@ -12507,5 +12507,116 @@ End Class
Assert.Equal("F:System.ValueTuple`2.Item1", cref)
End Sub
<Fact>
<WorkItem(39315, "https://github.com/dotnet/roslyn/issues/39315")>
Public Sub WriteDocumentationCommentXml_01()
Dim sources =
<compilation>
<file name="a.vb">
<![CDATA[
''' <summary> a.vb
''' </summary>
]]>
</file>
<file name="b.vb">
<![CDATA[
''' <summary> b.vb
''' </summary>
]]>
</file>
</compilation>
Using (New EnsureEnglishUICulture())
Dim comp = CreateCompilationWithMscorlib40(sources, parseOptions:=s_optionsDiagnoseDocComments)
Dim diags = DiagnosticBag.GetInstance()
DocumentationCommentCompiler.WriteDocumentationCommentXml(
comp,
assemblyName:=Nothing,
xmlDocStream:=Nothing,
diagnostics:=diags,
cancellationToken:=Nothing,
filterTree:=comp.SyntaxTrees(0))
AssertTheseDiagnostics(diags.ToReadOnlyAndFree(),
<errors><![CDATA[
BC42312: XML documentation comments must precede member or type declarations.
''' <summary> a.vb
~~~~~~~~~~~~~~~~
]]></errors>)
diags = DiagnosticBag.GetInstance()
DocumentationCommentCompiler.WriteDocumentationCommentXml(
comp,
assemblyName:=Nothing,
xmlDocStream:=Nothing,
diagnostics:=diags,
cancellationToken:=Nothing,
filterTree:=comp.SyntaxTrees(0),
filterSpanWithinTree:=New Text.TextSpan(0, 0))
Assert.Empty(diags.ToReadOnlyAndFree())
diags = DiagnosticBag.GetInstance()
DocumentationCommentCompiler.WriteDocumentationCommentXml(
comp,
assemblyName:=Nothing,
xmlDocStream:=Nothing,
diagnostics:=diags,
cancellationToken:=Nothing,
filterTree:=comp.SyntaxTrees(1))
AssertTheseDiagnostics(diags.ToReadOnlyAndFree(),
<errors><![CDATA[
BC42312: XML documentation comments must precede member or type declarations.
''' <summary> b.vb
~~~~~~~~~~~~~~~~
]]></errors>)
diags = DiagnosticBag.GetInstance()
DocumentationCommentCompiler.WriteDocumentationCommentXml(
comp,
assemblyName:=Nothing,
xmlDocStream:=Nothing,
diagnostics:=diags,
cancellationToken:=Nothing,
filterTree:=Nothing)
AssertTheseDiagnostics(diags.ToReadOnlyAndFree(),
<errors><![CDATA[
BC42312: XML documentation comments must precede member or type declarations.
''' <summary> a.vb
~~~~~~~~~~~~~~~~
BC42312: XML documentation comments must precede member or type declarations.
''' <summary> b.vb
~~~~~~~~~~~~~~~~
]]></errors>)
diags = DiagnosticBag.GetInstance()
DocumentationCommentCompiler.WriteDocumentationCommentXml(
comp,
assemblyName:=Nothing,
xmlDocStream:=Nothing,
diagnostics:=diags,
cancellationToken:=Nothing,
filterTree:=Nothing,
filterSpanWithinTree:=New Text.TextSpan(0, 0))
AssertTheseDiagnostics(diags.ToReadOnlyAndFree(),
<errors><![CDATA[
BC42312: XML documentation comments must precede member or type declarations.
''' <summary> a.vb
~~~~~~~~~~~~~~~~
BC42312: XML documentation comments must precede member or type declarations.
''' <summary> b.vb
~~~~~~~~~~~~~~~~
]]></errors>)
End Using
End Sub
End Class
End Namespace
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册