-
-
Notifications
You must be signed in to change notification settings - Fork 93
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
fixing another edge case related to comments + directives #235
Conversation
f9c8f22
to
00c85e9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, after seeing how this stack gets used, I retract my earlier comment that a List
would be better.
In dotnet, a Stack
implements IEnumerable
, so we can do a read-only iteration through it to evaluate Fits()
.
Since Js doesn't have a native Stack
structure, I can't speak for exactly what prettier used, but I'm guessing they couldn't iterate without mutating their stack, which is why they created a new one.
Src/CSharpier/DocSerializer.cs
Outdated
@@ -29,7 +29,11 @@ string PrintIndentedDocTree(Doc doc) | |||
case NullDoc: | |||
return indent + "Doc.Null"; | |||
case StringDoc stringDoc: | |||
return indent + "\"" + stringDoc.Value?.Replace("\"", "\\\"") + "\""; | |||
if (stringDoc.IsDirective) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I wonder if this would look better as a:
case StringDoc { IsDirective: true }:
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is now a giant SwitchExpression which CSharpier doesn't do the greatest job formatting. #237
I'm thinking of doing the following. Fits will be a little more complex, but because of how often it can hit it is probably worth it.
Although now that I type it out, I realize this approach will still be creating a new stack each time Fits gets hit... It could be modified to only create a stack if it needs to. I'll benchmark it and play around. I did benchmark Stack vs List vs LinkList for this, and List/LinkList were quite a bit faster than Stack, but that was most likely because of the .Reverse used to create the Stack inside of Fits. |
refactor docprinter a little ignore some properties in syntaxNodeComparer so that it gives you a better indication of the code that is failing the validation
d3fbae0
to
5ecf8c8
Compare
refactor docprinter a little
ignore some properties in syntaxNodeComparer so that it gives you a better indication of the code that is failing the validation