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.
Support for formatting a selection #708
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for formatting a selection #708
Changes from 1 commit
6640067
88beb85
0c0977d
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I’m not a fan of having a public API that requires the user to provide both
syntax
andsource
because that seems like redundant information. I think we should continue to have a public function that takes eithersyntax
orsource
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the syntax tree hold on to the source (I didn't see that when I did this two months ago 🙃, but I can look...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes,
syntax.description
gives you the source code. It does need to stitch the syntax tree back together from the individual tokens, so there is a use case for a function that takes both the syntax tree and the source as aString
, but I think that should not be a public function.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like having to regenerate the original source text if we already have it to start (which, of course, we do). And eventually we'll have a transformed syntax tree, and we still need to use the original source along with that. I think passing both makes the most sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar here. It feels redundant to pass both
syntax
andsource
to this function (also error prone if the two are not in sync).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment here. Since the whitespace linting uses
PrettyPrinter
to compare to the original source, we need to pass it along too.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does the printer pick up the whitespace characters that were dropped here? Ie. how does it know to format those but not anything in
text
? Seems like I’m missing something here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, we have to make sure our state variables are set correctly so that it does that correctly. That's what the next few lines do. 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m still missing how the whitespace characters that we’re shaving off with this are being printed.
If you have the following
Then I think this only adds
func foo()
to the output stream, right (no whitespace)? But the next token that we print is the{
, which doesn’t have any leading trivia (spaces are trailing trivia to)
).If those examples work because of some trivia re-attribution rule, how about the following?