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

Add GeneratedCodeAttribute to Generated code #621

Merged
merged 5 commits into from
Aug 10, 2022

Conversation

elachlan
Copy link
Contributor

@elachlan elachlan commented Jul 26, 2022

Closes #594

@ghost
Copy link

ghost commented Jul 26, 2022

CLA assistant check
All CLA requirements met.

@elachlan
Copy link
Contributor Author

@AArnott If you could give this a quick review that would be great.

Copy link
Member

@AArnott AArnott left a comment

Choose a reason for hiding this comment

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

Thanks for contributing. I think you're almost there.

src/Microsoft.Windows.CsWin32/Generator.cs Outdated Show resolved Hide resolved
@AArnott AArnott added the enhancement New feature or request label Aug 3, 2022
@elachlan elachlan requested a review from AArnott August 4, 2022 02:37
@elachlan
Copy link
Contributor Author

elachlan commented Aug 4, 2022

@AArnott, the remaining test failures are a bit of a strange one. They are all off by one tab space.

If you call AddAttributeLists and then afterwards WithLeadingTrivia, it adds an extra tab space for some reason. I have no idea how to fix it.

@AArnott
Copy link
Member

AArnott commented Aug 4, 2022

Thank you for getting us this far. I hope to look more into this today or tomorrow.

@elachlan
Copy link
Contributor Author

elachlan commented Aug 4, 2022

@sharwell this code causes the xml comment to have an extra leading tab white space:

typeDeclaration = typeDeclaration
                    .WithLeadingTrivia()
                    .AddAttributeLists(AttributeList().AddAttributes(GeneratedCodeAttribute))
                    .WithLeadingTrivia(typeDeclaration.GetLeadingTrivia());

The generated code attribute is:

private static readonly AttributeSyntax GeneratedCodeAttribute = Attribute(IdentifierName("global::System.CodeDom.Compiler.GeneratedCode"))
        .WithArgumentList(FixTrivia(AttributeArgumentList().AddArguments(
            AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(ThisAssembly.AssemblyName))),
            AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(ThisAssembly.AssemblyInformationalVersion))))));

It seems like an issue in Roslyn, but its more likely PEBKAC. Is there anything obvious I have missed?

@elachlan
Copy link
Contributor Author

elachlan commented Aug 8, 2022

@AArnott Youssef1313 pointed out in the roslyn issue that the problem is in WhitespaceRewriter. I'll let you know if I manage to solve it.

Edit: It looks like there is an issue in WhitespaceRewriter.VisitList. It seems to think that the XML comment's parent is the attribute and not the class declaration? Nothing else has this issue.

@Youssef1313
Copy link
Contributor

@elachlan Can you see if elachlan#1 fixes the issue?

@elachlan
Copy link
Contributor Author

elachlan commented Aug 9, 2022

I'll pull yours down now and check it.

@elachlan
Copy link
Contributor Author

elachlan commented Aug 9, 2022

@Youssef1313 I have pushed through some more changes around for loop indenting.

This is what its generating at the moment inside PAINTSTRUCT
image
I am not 100% sure, but there might be braces missing.

Edit: it might actually just be single line.

@elachlan
Copy link
Contributor Author

elachlan commented Aug 9, 2022

I gave up on the for loops.

I have fixed the other test issues. We can fix the rest of the white space issues in another PR.

@elachlan
Copy link
Contributor Author

elachlan commented Aug 9, 2022

@AArnott can you give this another review?

@elachlan
Copy link
Contributor Author

elachlan commented Aug 9, 2022

@Youssef1313 thank you for your help on this! It helped immensely.

Copy link
Member

@AArnott AArnott left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution. I would never have guessed this required so much work. I appreciate your dedication.

@AArnott AArnott merged commit 9deb003 into microsoft:main Aug 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider emitting GeneratedCodeAttribute on all generated types
3 participants