提交 75bc570f 编写于 作者: D Dustin Campbell

Make doc comment parsing for code model external elements a bit more robust

上级 98888e29
......@@ -57,6 +57,20 @@ protected virtual EnvDTE.vsCMAccess GetAccess()
return CodeModelService.GetAccess(LookupSymbol());
}
private static bool TryParseDocCommentXml(string text, out XElement xml)
{
try
{
xml = XElement.Parse(text);
return true;
}
catch (XmlException)
{
xml = null;
return false;
}
}
protected virtual string GetDocComment()
{
var symbol = LookupSymbol();
......@@ -73,13 +87,15 @@ protected virtual string GetDocComment()
}
XElement xml;
try
if (!TryParseDocCommentXml(documentationCommentXml, out xml))
{
xml = XElement.Parse(documentationCommentXml);
}
catch (XmlException)
{
return string.Empty;
// If we failed to parse, maybe it was because the XML fragment represents multiple elements.
// Try surrounding with <doc></doc> and parse again.
if (!TryParseDocCommentXml($"<doc>{documentationCommentXml}</doc>", out xml))
{
return string.Empty;
}
}
// Surround with <doc> element. Or replace <member> element with <doc>, if it exists.
......@@ -88,7 +104,7 @@ protected virtual string GetDocComment()
xml.Name = "doc";
xml.RemoveAttributes();
}
else
else if (xml.Name != "doc")
{
xml = new XElement("doc", xml);
}
......
......@@ -22,6 +22,20 @@ class C$$
TestDocComment(code, "<doc>" & vbCrLf & " <summary>This is my comment!</summary>" & vbCrLf & "</doc>")
End Sub
<ConditionalWpfFact(GetType(x86)), Trait(Traits.Feature, Traits.Features.CodeModel)>
Public Sub DocComment2()
Dim code =
<Code>
/// &lt;summary&gt;This is my comment!&lt;/summary&gt;
/// &lt;remarks /&gt;
class C$$
{
}
</Code>
TestDocComment(code, "<doc>" & vbCrLf & " <summary>This is my comment!</summary>" & vbCrLf & " <remarks />" & vbCrLf & "</doc>")
End Sub
#End Region
<ConditionalWpfFact(GetType(x86)), Trait(Traits.Feature, Traits.Features.CodeModel)>
......
......@@ -21,6 +21,19 @@ End Class
TestDocComment(code, "<doc>" & vbCrLf & " <summary>This is my comment!</summary>" & vbCrLf & "</doc>")
End Sub
<ConditionalWpfFact(GetType(x86)), Trait(Traits.Feature, Traits.Features.CodeModel)>
Public Sub DocComment2()
Dim code =
<Code>
''' &lt;summary&gt;This is my comment!&lt;/summary&gt;
''' &lt;remarks /&gt;
Class C$$
End Class
</Code>
TestDocComment(code, "<doc>" & vbCrLf & " <summary>This is my comment!</summary>" & vbCrLf & " <remarks />" & vbCrLf & "</doc>")
End Sub
#End Region
<ConditionalWpfFact(GetType(x86)), Trait(Traits.Feature, Traits.Features.CodeModel)>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册