Open Inspyro opened 9 years ago
All tokens and nodes created with the factory have zero-width elastic trivia leading and trailing by default. This type of trivia is used to indicate to the formatter that it is free to apply formatting rules in these places and change trivia typed by the user or identified by the parser.
The formatter may have some bugs related to the existence of this trivia.
Hi, after some hours of debugging I found a potential bug of Roslyn. When a PropertyDeclaration is generated with the SyntaxFactory a trailing whitespace with width 0 is automatically added. When the leading trivia of the next member is a multiline xml doc comment, it gets formatted wrong by the Formatter, because it is apparently confused by the trailing whitespace. When the trailing whitespace is removed from the generated PropertyDeclaration, the formatting works as expected.
Code sample:
(I know that the property declarations are incomplete, but the problem persists when you add the getter setter)
When the code is executed the output is:
which is wrong, because the second/third line of the multi line comment has a wrong format.
When the trailing trivia of member1 is removed the output is:
which seems (more) correct
I found out that in the first case with the trailing whitespace, the calculation of the intendationDelta in the CSharpTriviaFormater.FormatDocumentComment has a negative value, but should be 0.
Maybe the SyntaxFactory builds a wrong syntax tree, or the Formatter has a bug. Hope that helps making Roslyn even better.