Keep comments when printing a parsed query #1029
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
WIP WIP WIP
This follows attempt and discussion started at graphql/graphiql#578.
Opening this early to validate: am I going into the wall here?
Because the printer takes a parsed AST as an input, what this is doing for now is trying to keep comments in said parsed AST.
But is it something actually reasonable? Should comments be kept in the AST? If not, I'm not sure how to achieve this without changing the printer so that it takes the result of
lexer
as an input instead of the result ofparse
.I was recommended in the link above to take example from prettier which already supports printing comments (as well as other goodies such breaking arguments into multiple lines when a line gets too long), but being entirely new to both codebases, it's rather difficult for me to understand, at least for now.
I'm more than happy to spend more time on this as I do want to achieve this, but any help would be welcome here :)