Skip to content

Handle function pointer and xml normalization#51981

Merged
jcouv merged 7 commits intodotnet:mainfrom
Youssef1313:normalizewhitespace
Apr 2, 2021
Merged

Handle function pointer and xml normalization#51981
jcouv merged 7 commits intodotnet:mainfrom
Youssef1313:normalizewhitespace

Conversation

@Youssef1313
Copy link
Member

@Youssef1313 Youssef1313 commented Mar 19, 2021

Fixes #50664 (commit 1)
Fixes #49732 (commit 2)

@Youssef1313 Youssef1313 requested a review from a team as a code owner March 19, 2021 08:02
@ghost ghost added the Area-Compilers label Mar 19, 2021
@Youssef1313 Youssef1313 changed the title Handle function pointer normalization Handle function pointer and xml normalization Mar 19, 2021
}

// No space after asterisk in function pointer.
if (token.IsKind(SyntaxKind.AsteriskToken) && token.Parent.IsKind(SyntaxKind.FunctionPointerType))
Copy link
Member

@333fred 333fred Mar 19, 2021

Choose a reason for hiding this comment

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

It's a bit more complicated than this. The IDE rules I implemented are:

  1. If there is no calling convention, no spaces.
  2. If there is a calling convention, put a space between the asterisk and the calling convention. So, for example, delegate* unmanaged<void>. See the IDE spacing rules here: https://github.com/dotnet/roslyn/blob/main/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Rules/SpacingFormattingRule.cs#L321-L413. #Closed

Copy link
Member Author

@Youssef1313 Youssef1313 Mar 20, 2021

Choose a reason for hiding this comment

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

Thanks @333fred. This makes it much easier. #Closed

@333fred
Copy link
Member

333fred commented Mar 19, 2021

Done review pass (commit 2)

Comment on lines +584 to +595
// No space after the < in function pointer parameter lists
// delegate*<void
if (token.IsKind(SyntaxKind.LessThanToken) && token.Parent.IsKind(SyntaxKind.FunctionPointerParameterList))
{
return false;
}

// No space before the > in function pointer parameter lists
// delegate*<void>
if (next.IsKind(SyntaxKind.GreaterThanToken) && next.Parent.IsKind(SyntaxKind.FunctionPointerParameterList))
{
return false;
Copy link
Member Author

@Youssef1313 Youssef1313 Mar 20, 2021

Choose a reason for hiding this comment

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

The IDE spacing is using an IDE option, which I don't think is available to use here. I defaulted to the more common convention, which is no space before > and no space after <. #Resolved

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, the normalizer isn't customized. There's one normalization.


In reply to: 598105046 [](ancestors = 598105046)

TestNormalizeDeclaration("public (string prefix,string uri)Foo()", "public (string prefix, string uri) Foo()");
}

[Fact]
Copy link
Member Author

Choose a reason for hiding this comment

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

Tests are copy from IDE tests, except 2 tests that produce an invalid tree and have different behavior (which I think is acceptable):

[Fact]
public async Task FormatFunctionPointerWithUnrecognizedCallingConvention()
{
var content = @"
unsafe class C
{
delegate *invalid < int , int > functionPointer;
}";
var expected = @"
unsafe class C
{
delegate*invalid <int, int> functionPointer;
}";
await AssertFormatAsync(expected, content);
}
[Fact]
public async Task FormatFunctionPointerWithInvalidCallingConventionAndSpecifiers()
{
var content = @"
unsafe class C
{
delegate *invalid [ Cdecl , Thiscall ] < int , int > functionPointer;
}";
var expected = @"
unsafe class C
{
delegate*invalid [Cdecl, Thiscall]<int, int> functionPointer;
}";
await AssertFormatAsync(expected, content);
}

@Youssef1313 Youssef1313 requested a review from 333fred April 1, 2021 13:11
Copy link
Member

@333fred 333fred left a comment

Choose a reason for hiding this comment

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

LGTM (commit 7). Thanks for the ping, this had slipped off my radar. @dotnet/roslyn-compiler for a second review.

@jcouv jcouv added the Community The pull request was submitted by a contributor who is not a Microsoft employee. label Apr 2, 2021
Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

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

LGTM Thanks (iteration 7)

@jcouv jcouv enabled auto-merge (squash) April 2, 2021 04:28
@jcouv jcouv merged commit f48d930 into dotnet:main Apr 2, 2021
@ghost ghost added this to the Next milestone Apr 2, 2021
@Youssef1313 Youssef1313 deleted the normalizewhitespace branch April 2, 2021 06:01
@jcouv
Copy link
Member

jcouv commented Apr 2, 2021

Merged/squashed. Thanks @Youssef1313

@dibarbet dibarbet modified the milestones: Next, 16.10.P3 Apr 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-Compilers Community The pull request was submitted by a contributor who is not a Microsoft employee.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NormalizeWhitespace should handle function pointers NormalizeWhitespace corrupts, invalidates xml doc comments when xml tags have namespaces

4 participants