dsync icon indicating copy to clipboard operation
dsync copied to clipboard

WIP: try to use `quote` + `prettyplease`

Open hasezoey opened this issue 1 year ago • 0 comments

This PR is a POC (which may be extended upon) to use quote + prettyplease for code generation instead of a string.

limitations i have found while using quote + syn + prettyplease:

  • does not preserve empty new lines
  • doc-comments will either get formatted as /** */ if multiline
  • does not preserve comments (that are not doc-comments)
  • does not indent multiline doc-comments
  • doc-comments have to be done in a separate variable, because quote does not allow interpolation in a comment

aside from those problems there are some things which could be done, but i have not done yet:

  • re-order the functions so that only one buffer is required (cannot add a beginning impl and a end impl like a string)
  • refactor structs / functions to use proc-macro2 / syn types (as to not require so much syn::parse)

re #105

PS: i know the tests are failing, i have just included 2 updated test cases which cover the all the cases this PR touches, and to simplify a quick review


my personal opinion is that at least in the current state (see limitations), the string representation is a lot better; but we should maybe still store proc-macro2 / syn types in things like StructField or names, to maybe ensure they are valid idents and stuff

hasezoey avatar Feb 08 '24 17:02 hasezoey