Open DavidDudson opened 6 years ago
This is problem is still an active area of research, see https://github.com/camfort/reprinter. It's far from solved in scalafix with Patch.
I believe the state-of-the art in this space is what I describe here https://github.com/scalameta/scalameta/issues/1137#issuecomment-338434998 I've been meaning to either move the scala-syntax repo to scalafmt or scalameta. This would allow users to write Tree.transform and where applicable explicitly copy over comments where important tree nodes are deconstructed into other trees.
@olafurpg I have a rough idea that should work for scaladoc comments only...
The new backend uses a tree of "Contexts", it's almost done and should be this weekend.
The GeneratorInputContext
contains input tree, generators to apply, soon the semantic api etc.
This get's turned into a GeneratorOutputContext
which contains the input + the result.
Defn/Decl
in the tree when converting from Tree -> GeneratorInputContext
and add it as a field GeneratorInputContext
Defn/Decl
and enable/disable scaladoc preservation.Show[Syntax]
instance for GeneratorOutputContext which can handle doc comments.Notes:
Mentioned it gitter multiple times.
We will need to either pull in scalafix and/or handle it with a scalameta/contrib patch for transforming trees while retaining comments.