AttributeListSyntax
trivia appears to be lost after applying a code fix
#72088
Labels
Milestone
AttributeListSyntax
trivia appears to be lost after applying a code fix
#72088
Note that this issue might be related to #29611, which has been standing for very long.
I have developed some code fixes, one of them applies a new attribute and either adjusts or removes a previously existing attribute.
The code fix is here.
This issue is tracked by
Rekkonnect/GenericsAnalyzer#47
Debugging
When debugging the code, I place a breakpoint right after the return statement on the code fix (here), which assigns the resulting document to the
document
variable. Upon inspecting the variable, callingdocument.GetTextAsync(cancellationToken).Result.ToString()
gives me the resulting document, which includes all trivia as expected, which aligns with the expected source in the test case.I followed the rest of the process of asserting the code fix test case, and I found that the attribute after the newly placed attribute lacks leading syntax trivia, and thus appears at the start of the line, as it is eventually asserted.
At this point, when the assertion of the document's text begins, the trivia of the attribute node that was not removed seems to have lost its leading trivia.
I have no further information about how and where this issue is caused. I believe that there is some dark magic happening with the attribute's trivia during the node replacement.
Here are the tests that test the behavior of the code fix that I have written. The first test yields:
Expected:
Actual:
The text was updated successfully, but these errors were encountered: