Skip to content

Optionally preserve trailing spaces in layoutDiff #2360

@toinehartman

Description

@toinehartman

Is your feature request related to a problem? Please describe.
Since #2031, we have layoutDiff, a useful tool to compute layout differences between trees. An obvious use case is writing a formatter (#2346, usethesource/rascal-language-servers#677).

Formatting can accept options, one of which is 'preserve/trim trailing spaces' - especially useful when formatting existing code without generating huge diffs. Whether using Rascal's declarative formatting tools (toBox o format) or custom/external ones, layoutDiff is the logical place to do this, in the spirit of its existing copyComments toggle.

Describe the solution you'd like
Add an option preserveTrailingWhitespace = false to layoutDiff, which copies trailing whitespace from the original tree to the modified one on demand.

Describe alternatives you've considered

  • Leaving the implementation to DSL developers
  • Adding the functionality to Tree2Box

Additional context
Came up during the design of formatting support for DSLs: usethesource/rascal-language-servers#677

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions