Replies: 1 comment
-
See also #1073 for additional examples and context |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hey folks!
Yesterday on Discord, we discussed the possibility of having a new, optional execution mode to Topiary, in which idempotency would not be checked, but instead we would recursively call Topiary on its own output, until a fixed point is reached (or some hardcoded limit is hit).
The rationale is that some "natural" formatting operations are not possible with Topiary's current semantics, due to the locality of the tree-sitter queries, but would be possible with the execution mode I described above. It would be an escape hatch, and could be very costly in worst-case scenarios (e.g. formatting loops), but it shouldn't be very costly to implement.
For the record, the use case we discussed was something like the following:
The problem was that
foo
s are supposed to be followed with a softline, whilebar
s are supposed to be followed by a hardline.Ideally, the code above would be formatted as:
The rules that immediately come to mind don't work:
(foo (_) @prepend_softline ) (bar (_) @prepend_hardline )
Indeed, on the first pass the softlines wouldn't get expanded, and the result would be
The formatting would only be correct after the second pass.
I believe there currently is no way for Topiary to get the correct result in one pass, nor do I see any easy addition/modification to the engine to make it possible.
Do you have opinions on the matter?
Beta Was this translation helpful? Give feedback.
All reactions