Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle records in documentation comments in IDE side #52737

Merged
merged 2 commits into from
May 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,40 @@ class C
VerifyTypingCharacter(code, expected);
}

[WpfFact, Trait(Traits.Feature, Traits.Features.DocumentationComments)]
public void TypingCharacter_Record()
{
var code =
@"//$$
record R;";

var expected =
@"/// <summary>
/// $$
/// </summary>
record R;";

VerifyTypingCharacter(code, expected);
}

[WpfFact, Trait(Traits.Feature, Traits.Features.DocumentationComments)]
public void TypingCharacter_RecordWithPositionalParameters()
{
var code =
@"//$$
record R(string S, int I);";

var expected =
@"/// <summary>
/// $$
/// </summary>
/// <param name=""S""></param>
/// <param name=""I""></param>
record R(string S, int I);";

VerifyTypingCharacter(code, expected);
}

[WpfFact, Trait(Traits.Feature, Traits.Features.DocumentationComments)]
public void TypingCharacter_Class_NewLine()
{
Expand Down Expand Up @@ -1467,6 +1501,36 @@ class C
VerifyInsertCommentCommand(code, expected);
}

[WpfFact, Trait(Traits.Feature, Traits.Features.DocumentationComments)]
public void Command_Record()
{
var code = "record R$$;";

var expected =
@"/// <summary>
/// $$
/// </summary>
record R;";

VerifyInsertCommentCommand(code, expected);
}

[WpfFact, Trait(Traits.Feature, Traits.Features.DocumentationComments)]
public void Command_RecordWithPositionalParameters()
{
var code = "record R$$(string S, int I);";

var expected =
@"/// <summary>
/// $$
/// </summary>
/// <param name=""S""></param>
/// <param name=""I""></param>
record R(string S, int I);";

VerifyInsertCommentCommand(code, expected);
}

[WorkItem(4817, "https://github.com/dotnet/roslyn/issues/4817")]
[WpfFact, Trait(Traits.Feature, Traits.Features.DocumentationComments)]
public void Command_Class_AutoGenerateXmlDocCommentsOff()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ protected override bool SupportsDocumentationComments(MemberDeclarationSyntax me
switch (member.Kind())
{
case SyntaxKind.ClassDeclaration:
case SyntaxKind.RecordDeclaration:
case SyntaxKind.InterfaceDeclaration:
case SyntaxKind.StructDeclaration:
case SyntaxKind.DelegateDeclaration:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,32 +114,6 @@ public static TypeParameterListSyntax GetTypeParameterList(this MemberDeclaratio
return null;
}

public static BaseParameterListSyntax GetParameterList(this MemberDeclarationSyntax member)
{
if (member != null)
{
switch (member.Kind())
{
case SyntaxKind.DelegateDeclaration:
return ((DelegateDeclarationSyntax)member).ParameterList;
case SyntaxKind.MethodDeclaration:
return ((MethodDeclarationSyntax)member).ParameterList;
case SyntaxKind.ConstructorDeclaration:
return ((ConstructorDeclarationSyntax)member).ParameterList;
case SyntaxKind.DestructorDeclaration:
return ((DestructorDeclarationSyntax)member).ParameterList;
case SyntaxKind.IndexerDeclaration:
return ((IndexerDeclarationSyntax)member).ParameterList;
case SyntaxKind.OperatorDeclaration:
return ((OperatorDeclarationSyntax)member).ParameterList;
case SyntaxKind.ConversionOperatorDeclaration:
return ((ConversionOperatorDeclarationSyntax)member).ParameterList;
}
}

return null;
}

public static MemberDeclarationSyntax WithParameterList(
this MemberDeclarationSyntax member,
BaseParameterListSyntax parameterList)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,8 @@ node is UsingStatementSyntax ||
_ => null,
};

public static BaseParameterListSyntax? GetParameterList(this SyntaxNode declaration)
=> declaration.Kind() switch
public static BaseParameterListSyntax? GetParameterList(this SyntaxNode? declaration)
=> declaration?.Kind() switch
{
SyntaxKind.DelegateDeclaration => ((DelegateDeclarationSyntax)declaration).ParameterList,
SyntaxKind.MethodDeclaration => ((MethodDeclarationSyntax)declaration).ParameterList,
Expand All @@ -270,6 +270,7 @@ node is UsingStatementSyntax ||
SyntaxKind.ParenthesizedLambdaExpression => ((ParenthesizedLambdaExpressionSyntax)declaration).ParameterList,
SyntaxKind.LocalFunctionStatement => ((LocalFunctionStatementSyntax)declaration).ParameterList,
SyntaxKind.AnonymousMethodExpression => ((AnonymousMethodExpressionSyntax)declaration).ParameterList,
SyntaxKind.RecordDeclaration => ((RecordDeclarationSyntax)declaration).ParameterList,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note to @jcouv to have this in the record-struct branch.

_ => null,
};

Expand Down