-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Handle properly stringifying multiline macro expressions #15305
base: master
Are you sure you want to change the base?
Handle properly stringifying multiline macro expressions #15305
Conversation
Hm, but if the expression only has a newline at one end it'll be different, right? {%
a = 1 %}
{% b = 1
%} This presumably stringifies to: {%
a = 1
%}
{% b = 1 %} Also other whitespace isn't repeated truthfully either. |
If you have code like: {%
a = 1 %}
{% b = 1
%} and you run the formatter on it, you get: {%
a = 1
%}
{% b = 1 %} So this at least makes things consistent with that. |
Pushed up another commit to better handle indentation within the stringified nodes. E.g. macro finished
{% verbatim do %}
{%
10
20
%}
{% end %}
end Its string representation is now the same, instead of: macro finished
{% verbatim do %}
{%
10
20
%}
{% end %}
end |
Ended up refactoring things one last time. Realized I could do this without touching the AST representation at all and just handle it based on the start/end location of the nodes themselves. So this PR only touches |
I wonder if it could be feasible to keep track of line numbers in the The implementation would consider each node's location relative to each other. If |
@straight-shoota I think it should definitely be possible, but would you be opposed to leaving that for another PR to address #15307? This PR is already a good start and is the basis of some other PRs I have in the works. EDIT: Actually one problem might be that |
I'm not super convinced about the implementation in this PR because it just addresses some symptoms, not the problem from the bottom up. It's basically just shifting error cases around, not really solving anything. |
👍 Alright, I'll see about doing another refactor to address #15307 in this PR in that case. I'll mark it as draft for now in that case. |
Alright @straight-shoota, pushed up another commit that handles significant whitespace as well. Tested against EDIT: Nevermind, spoke too soon. Found some additional edge cases I'll need to address. |
some minor cleanup
Update other specs to use new format
Given the following code:
Its
to_s
representation before this PR:and after:
This PR also addresses #15307:
is now properly stringified as:
instead of: