Replies: 2 comments
-
Topiary works by formatting known subtrees, per the language's grammar, which won't necessarily correspond with line ranges. For example, consider the following:
The formatting of lines 2-4 depend on the context introduced in line 1. As such, at the very least, such a functionality would have to ascend the tree. My gut feeling is that the answer to "how far up the tree will it need go?" will be arbitrary. For example, L3 in the above, in isolation, takes its indentation ultimately from the Maybe an option would be:
In the pathological case -- where the line range is the last line in a file -- Topiary would generate the formatting for the entire file and throw almost all of it away. Regardless, it feels like a wasteful operation. I assume this option exists in Eclipse for legacy reasons; when formatting an entire file could take some time. Given that Topiary is relatively fast, outside its startup overhead (which we're thinking of ways to mitigate), I'm not sure this achieves much. That said, I understand your use-case and, on top of that, the same mechanism could be used to achieve incremental formatting, which is another point that's come up (but I can't find the issue/discussion now 😅) It would be interesting to know how Eclipse does this; maybe it can be done without wasting so much effort. (Or, maybe, given how fast formatting tends to be, that wasted effort isn't worth worrying about!) Other thoughts, @tweag/topiary-core-team? |
Beta Was this translation helpful? Give feedback.
-
Unfortunately @Xophmeister, I think even the option you're suggesting would introduce problems: "belonging to a given line" is a property that isn't preserved by formatting. For example, consider the following incorrectly formatted code:
Assume the correctly formatted version is:
What would it mean to format only line 2? If we're naive about this and use the method above, it would give us something like:
That's not even valid code. I suppose we could do something like formatting the smallest subset of lines containing the input range, whose content is preserved by formatting. I'm not even sure that can be properly defined, though. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi there!
Does topiary allow formatting only part of the file? I mean something like enumeration of line ranges. I find such feature of formatter especially useful in context of legacy projects where it allows to gradually reformat content as it is changed: only vcs alterd lines are formatted each commit. Something known for Eclipse users as:
Of course I'm not expecting vcs integration to check for changed lines - just additional argument with line ranges to take into account.
Beta Was this translation helpful? Give feedback.
All reactions