-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Fix trailing formatting edit when range ends mid-token #50082
Conversation
// with a selection from the beginning of the line to the space inside the curly braces, | ||
// inclusive. We would expect a format-selection would delete the space (if rules apply), | ||
// but in order to do that, we need to process the pair ["{", "}"], but we stopped processing | ||
// just before getting there. This block handles this trailing edit. |
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.
This comment should have been included with #46875.
// produce bogus edits if we try to `processPair`. Recall that the point of this logic is | ||
// to perform a trailing edit at the end of the selection range: but there can be no valid | ||
// edit in the middle of a token where the range ended, so if we have a non-contiguous | ||
// pair here, we're already done and we can ignore it. |
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.
This comment describes the fix for this bug.
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.
LGTM, I'm always suspicious of the !
but they're at least consistent with the other side-effecty previous variables, so...
Yeah, it’s correlated with the existence of |
// but in order to do that, we need to process the pair ["{", "}"], but we stopped processing | ||
// just before getting there. This block handles this trailing edit. |
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.
// but in order to do that, we need to process the pair ["{", "}"], but we stopped processing | |
// just before getting there. This block handles this trailing edit. | |
// but in order to do that, we need to process the pair ["{", "}"]. | |
// This block handles this trailing edit by ensuring we continue processing. | |
// the pair of tokens that the range intersects. |
const tokenInfo = | ||
formattingScanner.isOnEOF() ? formattingScanner.readEOFTokenRange() : | ||
formattingScanner.isOnToken() ? formattingScanner.readTokenInfo(enclosingNode).token : | ||
undefined; | ||
|
||
if (tokenInfo) { | ||
if (tokenInfo && tokenInfo.pos === previousRangeTriviaEnd!) { | ||
// We need to check that tokenInfo and previousRange are contiguous: the `originalRange` |
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.
// We need to check that tokenInfo and previousRange are contiguous: the `originalRange` | |
// We need to check that previousRange and tokenInfo are contiguous since the `originalRange` |
Fixes #50076