question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Additional tab white space on XML comment leading trivia if Attribute is added prior

See original GitHub issue

I am currently working on this PR for CsWin32: https://github.com/microsoft/CsWin32/pull/621

We have this code that causes the xml comment to have an extra leading tab white space:

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

typeDeclaration is MemberDeclarationSyntax.

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))))));

If we do not add the attribute, then the leading trivia xml comment is formatted correctly.

Am I missing something obvious?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
Youssef1313commented, Aug 8, 2022
typeDeclaration = typeDeclaration
                    .WithLeadingTrivia()
                    .AddAttributeLists(AttributeList().AddAttributes(GeneratedCodeAttribute))
                    .WithLeadingTrivia(typeDeclaration.GetLeadingTrivia());

I’m not seeing this line being hit with typeDeclaration corresponding to PInvoke in test TestSimpleMethod. Can you confirm?

It looks like trivia is messed up at WhitespaceRewriter

0reactions
Youssef1313commented, Aug 9, 2022

Hope https://github.com/elachlan/CsWin32/pull/1 corrects the implementation 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is there any way to preserve white space in C# XML ...
I used <br /> to indicate individual new lines (this works as of VS 2019), but I can't insert spaces or tabs. I...
Read more >
SyntaxFactory Class (Microsoft.CodeAnalysis.CSharp)
Determines if two syntax nodes are the same, disregarding trivia differences. ... Creates an xml documentation comment that abstracts xml syntax creation.
Read more >
XML Schema Restrictions/Facets
Restrictions are used to define acceptable values for XML elements or attributes. Restrictions on XML elements are called facets.
Read more >
Creating an Editable Textarea That Supports Syntax- ...
We can add some CSS that basically allows the <textarea> and the <pre><code> elements to be sized and spaced consistently. #editing, # ...
Read more >
A Roadmap to XML Parsers in Python
In this tutorial, you'll learn what XML parsers are available in Python and how to pick the right parsing model for your specific...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found