未验证 提交 9424cbdd 编写于 作者: S Sam Harwell 提交者: GitHub

Merge pull request #33547 from sharwell/classify-quick-info

Classify paramref and typeparamref in Quick Info
......@@ -478,6 +478,122 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense
AssertEqualAdornments(expected, container)
End Sub
<WpfFact, Trait(Traits.Feature, Traits.Features.QuickInfo)>
<WorkItem(33546, "https://github.com/dotnet/roslyn/issues/33546")>
Public Async Sub QuickInfoForParameterReference()
Dim workspace =
<Workspace>
<Project Language="C#" CommonReferences="true">
<Document>
using System.Threading;
class MyClass {
/// &lt;summary&gt;
/// The parameter is &lt;paramref name="p"/&gt;.
/// &lt;/summary&gt;
void MyMethod(CancellationToken p) {
MyM$$ethod(CancellationToken.None);
}
}
</Document>
</Project>
</Workspace>
Dim codeAnalysisQuickInfoItem = Await GetQuickInfoItemAsync(workspace, LanguageNames.CSharp)
Dim trackingSpan = New Mock(Of ITrackingSpan) With {
.DefaultValue = DefaultValue.Mock
}
Dim intellisenseQuickInfo = Await IntellisenseQuickInfoBuilder.BuildItemAsync(trackingSpan.Object, codeAnalysisQuickInfoItem, Nothing, Nothing, CancellationToken.None)
Assert.NotNull(intellisenseQuickInfo)
Dim container = Assert.IsType(Of ContainerElement)(intellisenseQuickInfo.Item)
Dim expected = New ContainerElement(
ContainerElementStyle.Stacked Or ContainerElementStyle.VerticalPadding,
New ContainerElement(
ContainerElementStyle.Stacked,
New ContainerElement(
ContainerElementStyle.Wrapped,
New ImageElement(New ImageId(KnownImageIds.ImageCatalogGuid, KnownImageIds.MethodPrivate)),
New ClassifiedTextElement(
New ClassifiedTextRun(ClassificationTypeNames.Keyword, "void"),
New ClassifiedTextRun(ClassificationTypeNames.WhiteSpace, " "),
New ClassifiedTextRun(ClassificationTypeNames.ClassName, "MyClass"),
New ClassifiedTextRun(ClassificationTypeNames.Punctuation, "."),
New ClassifiedTextRun(ClassificationTypeNames.MethodName, "MyMethod"),
New ClassifiedTextRun(ClassificationTypeNames.Punctuation, "("),
New ClassifiedTextRun(ClassificationTypeNames.StructName, "CancellationToken"),
New ClassifiedTextRun(ClassificationTypeNames.WhiteSpace, " "),
New ClassifiedTextRun(ClassificationTypeNames.ParameterName, "p"),
New ClassifiedTextRun(ClassificationTypeNames.Punctuation, ")"))),
New ClassifiedTextElement(
New ClassifiedTextRun(ClassificationTypeNames.Text, "The parameter is"),
New ClassifiedTextRun(ClassificationTypeNames.WhiteSpace, " "),
New ClassifiedTextRun(ClassificationTypeNames.ParameterName, "p"),
New ClassifiedTextRun(ClassificationTypeNames.Text, "."))))
AssertEqualAdornments(expected, container)
End Sub
<WpfFact, Trait(Traits.Feature, Traits.Features.QuickInfo)>
<WorkItem(33546, "https://github.com/dotnet/roslyn/issues/33546")>
Public Async Sub QuickInfoForTypeParameterReference()
Dim workspace =
<Workspace>
<Project Language="C#" CommonReferences="true">
<Document>
using System.Threading;
class MyClass {
/// &lt;summary&gt;
/// The type parameter is &lt;typeparamref name="T"/&gt;.
/// &lt;/summary&gt;
void MyMethod&lt;T&gt;() {
MyM$$ethod&lt;int&gt;();
}
}
</Document>
</Project>
</Workspace>
Dim codeAnalysisQuickInfoItem = Await GetQuickInfoItemAsync(workspace, LanguageNames.CSharp)
Dim trackingSpan = New Mock(Of ITrackingSpan) With {
.DefaultValue = DefaultValue.Mock
}
Dim intellisenseQuickInfo = Await IntellisenseQuickInfoBuilder.BuildItemAsync(trackingSpan.Object, codeAnalysisQuickInfoItem, Nothing, Nothing, CancellationToken.None)
Assert.NotNull(intellisenseQuickInfo)
Dim container = Assert.IsType(Of ContainerElement)(intellisenseQuickInfo.Item)
Dim expected = New ContainerElement(
ContainerElementStyle.Stacked Or ContainerElementStyle.VerticalPadding,
New ContainerElement(
ContainerElementStyle.Stacked,
New ContainerElement(
ContainerElementStyle.Wrapped,
New ImageElement(New ImageId(KnownImageIds.ImageCatalogGuid, KnownImageIds.MethodPrivate)),
New ClassifiedTextElement(
New ClassifiedTextRun(ClassificationTypeNames.Keyword, "void"),
New ClassifiedTextRun(ClassificationTypeNames.WhiteSpace, " "),
New ClassifiedTextRun(ClassificationTypeNames.ClassName, "MyClass"),
New ClassifiedTextRun(ClassificationTypeNames.Punctuation, "."),
New ClassifiedTextRun(ClassificationTypeNames.MethodName, "MyMethod"),
New ClassifiedTextRun(ClassificationTypeNames.Punctuation, "<"),
New ClassifiedTextRun(ClassificationTypeNames.Keyword, "int"),
New ClassifiedTextRun(ClassificationTypeNames.Punctuation, ">"),
New ClassifiedTextRun(ClassificationTypeNames.Punctuation, "("),
New ClassifiedTextRun(ClassificationTypeNames.Punctuation, ")"))),
New ClassifiedTextElement(
New ClassifiedTextRun(ClassificationTypeNames.Text, "The type parameter is"),
New ClassifiedTextRun(ClassificationTypeNames.WhiteSpace, " "),
New ClassifiedTextRun(ClassificationTypeNames.TypeParameterName, "T"),
New ClassifiedTextRun(ClassificationTypeNames.Text, "."))))
AssertEqualAdornments(expected, container)
End Sub
Private Async Function GetQuickInfoItemAsync(workspaceDefinition As XElement, language As String) As Task(Of QuickInfoItem)
Using workspace = TestWorkspace.Create(workspaceDefinition)
Dim solution = workspace.CurrentSolution
......
......@@ -186,7 +186,7 @@ private static void AppendTextFromNode(FormatterState state, XNode node, Compila
{
foreach (var attribute in element.Attributes())
{
AppendTextFromAttribute(state, element, attribute, attributeNameToParse: DocumentationCommentXmlNames.CrefAttributeName);
AppendTextFromAttribute(state, element, attribute, attributeNameToParse: DocumentationCommentXmlNames.CrefAttributeName, SymbolDisplayPartKind.Text);
}
return;
......@@ -195,9 +195,10 @@ private static void AppendTextFromNode(FormatterState state, XNode node, Compila
else if (name == DocumentationCommentXmlNames.ParameterReferenceElementName ||
name == DocumentationCommentXmlNames.TypeParameterReferenceElementName)
{
var kind = name == DocumentationCommentXmlNames.ParameterReferenceElementName ? SymbolDisplayPartKind.ParameterName : SymbolDisplayPartKind.TypeParameterName;
foreach (var attribute in element.Attributes())
{
AppendTextFromAttribute(state, element, attribute, attributeNameToParse: DocumentationCommentXmlNames.NameAttributeName);
AppendTextFromAttribute(state, element, attribute, attributeNameToParse: DocumentationCommentXmlNames.NameAttributeName, kind);
}
return;
......@@ -223,13 +224,13 @@ private static void AppendTextFromNode(FormatterState state, XNode node, Compila
}
}
private static void AppendTextFromAttribute(FormatterState state, XElement element, XAttribute attribute, string attributeNameToParse)
private static void AppendTextFromAttribute(FormatterState state, XElement element, XAttribute attribute, string attributeNameToParse, SymbolDisplayPartKind kind)
{
var attributeName = attribute.Name.LocalName;
if (attributeNameToParse == attributeName)
{
state.AppendParts(
CrefToSymbolDisplayParts(attribute.Value, state.Position, state.SemanticModel, state.Format).ToTaggedText());
CrefToSymbolDisplayParts(attribute.Value, state.Position, state.SemanticModel, state.Format, kind).ToTaggedText());
}
else
{
......@@ -241,7 +242,7 @@ private static void AppendTextFromAttribute(FormatterState state, XElement eleme
}
internal static IEnumerable<SymbolDisplayPart> CrefToSymbolDisplayParts(
string crefValue, int position, SemanticModel semanticModel, SymbolDisplayFormat format = null)
string crefValue, int position, SemanticModel semanticModel, SymbolDisplayFormat format = null, SymbolDisplayPartKind kind = SymbolDisplayPartKind.Text)
{
// first try to parse the symbol
if (semanticModel != null)
......@@ -261,7 +262,7 @@ private static void AppendTextFromAttribute(FormatterState state, XElement eleme
// if any of that fails fall back to just displaying the raw text
return SpecializedCollections.SingletonEnumerable(
new SymbolDisplayPart(SymbolDisplayPartKind.Text, symbol: null, text: TrimCrefPrefix(crefValue)));
new SymbolDisplayPart(kind, symbol: null, text: TrimCrefPrefix(crefValue)));
}
private static string TrimCrefPrefix(string value)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册