提交 b595e1f4 编写于 作者: B Brett Forsgren

Merge pull request #5559 from brettfo/doc-comment-attributes

process all attributes in XML documentation comments
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
......@@ -50,24 +51,26 @@ private static string GetBannerText(DocumentationCommentTriviaSyntax documentati
else if (node is XmlEmptyElementSyntax)
{
var e = (XmlEmptyElementSyntax)node;
var cref = e.Attributes.OfType<XmlCrefAttributeSyntax>().FirstOrDefault();
if (cref != null)
foreach (var attribute in e.Attributes)
{
sb.Append(" ");
sb.Append(cref.Cref.ToString());
}
var nameattribute = e.Attributes.OfType<XmlNameAttributeSyntax>().FirstOrDefault();
if (nameattribute != null)
{
sb.Append(" ");
sb.Append(nameattribute.Identifier.Identifier.Text);
}
var langword = e.Attributes.OfType<XmlTextAttributeSyntax>().FirstOrDefault(a => a.Name.LocalName.ToString() == "langword");
if (langword != null)
{
AppendTextTokens(sb, langword.TextTokens);
if (attribute is XmlCrefAttributeSyntax)
{
sb.Append(" ");
sb.Append(((XmlCrefAttributeSyntax)attribute).Cref.ToString());
}
else if (attribute is XmlNameAttributeSyntax)
{
sb.Append(" ");
sb.Append(((XmlNameAttributeSyntax)attribute).Identifier.Identifier.Text);
}
else if (attribute is XmlTextAttributeSyntax)
{
AppendTextTokens(sb, ((XmlTextAttributeSyntax)attribute).TextTokens);
}
else
{
Debug.Fail($"Unexpected XML syntax kind {attribute.Kind()}");
}
}
}
}
......
......@@ -391,7 +391,7 @@ public void CrefInSummary()
"{",
" /// <summary>",
" /// Summary with <see cref=\"SeeClass\" />, <seealso cref=\"SeeAlsoClass\" />, ",
" /// <see langword=\"null\" />, <typeparamref name=\"T\" />, and <paramref name=\"t\" />.",
" /// <see langword=\"null\" />, <typeparamref name=\"T\" />, <paramref name=\"t\" />, and <see unsupported-attribute=\"not-supported\" />.",
" /// </summary>",
" public void M<T>(T t) { }",
"}");
......@@ -402,8 +402,8 @@ public void CrefInSummary()
var docComment = (DocumentationCommentTriviaSyntax)trivia.Single(t => t.HasStructure).GetStructure();
var actualRegion = GetRegion(docComment);
var expectedRegion = new OutliningSpan(
TextSpan.FromBounds(16, 218),
"/// <summary> Summary with SeeClass , SeeAlsoClass , null , T , and t .",
TextSpan.FromBounds(16, 265),
"/// <summary> Summary with SeeClass , SeeAlsoClass , null , T , t , and not-supported .",
autoCollapse: true);
AssertRegion(expectedRegion, actualRegion);
......
......@@ -4184,5 +4184,27 @@ void M()
",
Exceptions($"\r\n{WorkspacesResources.Exceptions}\r\n MyException1\r\n MyException2\r\n int\r\n double\r\n Not_A_Class_But_Still_Displayed"));
}
[Fact, Trait(Traits.Feature, Traits.Features.QuickInfo)]
[WorkItem(1516, "https://github.com/dotnet/roslyn/issues/1516")]
public void QuickInfoWithNonStandardSeeAttributesAppear()
{
Test(@"
class C
{
/// <summary>
/// <see cref=""System.String"" />
/// <see href=""http://microsoft.com"" />
/// <see langword=""null"" />
/// <see unsupported-attribute=""cat"" />
/// </summary>
void M()
{
M$$();
}
}
",
Documentation(@"string http://microsoft.com null cat"));
}
}
}
......@@ -26,22 +26,19 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.Outlining
AppendTextTokens(sb, textTokens)
ElseIf node.Kind() = SyntaxKind.XmlEmptyElement Then
Dim elementNode = DirectCast(node, XmlEmptyElementSyntax)
Dim cref = elementNode.Attributes.OfType(Of XmlCrefAttributeSyntax).FirstOrDefault()
If cref IsNot Nothing Then
sb.Append(" ")
sb.Append(cref.Reference.ToString())
End If
Dim nameattribute = elementNode.Attributes.OfType(Of XmlNameAttributeSyntax).FirstOrDefault()
If nameattribute IsNot Nothing Then
sb.Append(" ")
sb.Append(nameattribute.Reference.ToString())
End If
Dim langword = elementNode.Attributes.OfType(Of XmlAttributeSyntax).FirstOrDefault(Function(a) a.Name.ToString() = "langword")
If langword IsNot Nothing Then
AppendTextTokens(sb, DirectCast(langword.Value, XmlStringSyntax).TextTokens)
End If
For Each attribute In elementNode.Attributes
If TypeOf attribute Is XmlCrefAttributeSyntax Then
sb.Append(" ")
sb.Append(DirectCast(attribute, XmlCrefAttributeSyntax).Reference.ToString())
ElseIf TypeOf attribute Is XmlNameAttributeSyntax Then
sb.Append(" ")
sb.Append(DirectCast(attribute, XmlNameAttributeSyntax).Reference.ToString())
ElseIf TypeOf attribute Is XmlAttributeSyntax Then
AppendTextTokens(sb, DirectCast(DirectCast(attribute, XmlAttributeSyntax).Value, XmlStringSyntax).TextTokens)
Else
Debug.Fail($"Unexpected XML syntax kind {attribute.Kind()}")
End If
Next
End If
Next
......
......@@ -236,7 +236,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.Outlining
Dim tree = ParseLines("Class C",
" ''' <summary>",
" ''' Summary with <see cref=""SeeClass"" />, <seealso cref=""SeeAlsoClass"" />,",
" ''' <see langword=""Nothing"" />, <typeparamref name=""T"" />, and <paramref name=""t"" />.",
" ''' <see langword=""Nothing"" />, <typeparamref name=""T"" />, <paramref name=""t"" />, and <see unsupported-attribute=""not-supported"" />.",
" ''' </summary>",
" Sub M(Of T)(t as T)",
" End Sub",
......@@ -248,8 +248,8 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.Outlining
Dim docComment = DirectCast(trivia.Single(Function(t) t.HasStructure).GetStructure(), DocumentationCommentTriviaSyntax)
Dim actualRegion = GetRegion(docComment)
Dim expectedRegion = New OutliningSpan(
TextSpan.FromBounds(13, 217),
"''' <summary> Summary with SeeClass , SeeAlsoClass , Nothing , T , and t .",
TextSpan.FromBounds(13, 264),
"''' <summary> Summary with SeeClass , SeeAlsoClass , Nothing , T , t , and not-supported .",
autoCollapse:=True)
AssertRegion(expectedRegion, actualRegion)
......
......@@ -2059,5 +2059,24 @@ End Namespace
Exceptions($"{vbCrLf}{WorkspacesResources.Exceptions}{vbCrLf} MyException1{vbCrLf} MyException2{vbCrLf} Integer{vbCrLf} Double{vbCrLf} Not_A_Class_But_Still_Displayed"))
End Sub
<Fact, Trait(Traits.Feature, Traits.Features.QuickInfo)>
<WorkItem(1516, "https://github.com/dotnet/roslyn/issues/1516")>
Public Sub QuickInfoWithNonStandardSeeAttributesAppear()
Test("
Class C
''' <summary>
''' <see cref=""System.String"" />
''' <see href=""http://microsoft.com"" />
''' <see langword=""Nothing"" />
''' <see unsupported-attribute=""cat"" />
''' </summary>
Sub M()
M$$()
End Sub
End Class
",
Documentation("String http://microsoft.com Nothing cat"))
End Sub
End Class
End Namespace
......@@ -156,13 +156,21 @@ private static void AppendTextFromNode(FormatterState state, XNode node, Compila
if (name == "see" ||
name == "seealso")
{
AppendTextFromAttribute(state, element, "cref");
foreach (var attribute in element.Attributes())
{
AppendTextFromAttribute(state, element, attribute, attributeNameToParse: "cref");
}
return;
}
else if (name == "paramref" ||
name == "typeparamref")
{
AppendTextFromAttribute(state, element, "name");
foreach (var attribute in element.Attributes())
{
AppendTextFromAttribute(state, element, attribute, attributeNameToParse: "name");
}
return;
}
......@@ -182,15 +190,20 @@ private static void AppendTextFromNode(FormatterState state, XNode node, Compila
}
}
private static void AppendTextFromAttribute(FormatterState state, XElement element, string attributeName)
private static void AppendTextFromAttribute(FormatterState state, XElement element, XAttribute attribute, string attributeNameToParse)
{
var attribute = element.Attribute(attributeName);
if (attribute == null)
var attributeName = attribute.Name.LocalName;
if (attributeNameToParse == attributeName)
{
return;
state.AppendParts(CrefToSymbolDisplayParts(attribute.Value, state.Position, state.SemanticModel, state.Format));
}
else
{
var displayKind = attributeName == "langword"
? SymbolDisplayPartKind.Keyword
: SymbolDisplayPartKind.Text;
state.AppendParts(SpecializedCollections.SingletonEnumerable(new SymbolDisplayPart(kind: displayKind, symbol: null, text: attribute.Value)));
}
state.AppendParts(CrefToSymbolDisplayParts(attribute.Value, state.Position, state.SemanticModel, state.Format));
}
internal static IEnumerable<SymbolDisplayPart> CrefToSymbolDisplayParts(string crefValue, int position, SemanticModel semanticModel, SymbolDisplayFormat format = null)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册