Render error caret for the last character of the parsing context - #627
Open
fudianchn wants to merge 1 commit into
Open
Render error caret for the last character of the parsing context#627fudianchn wants to merge 1 commit into
fudianchn wants to merge 1 commit into
Conversation
ParsingException.getMessage() guards the caret rendering with `column < context.length()`, but `column` is 1-indexed (the caret is drawn at position `column - 1`), so when the error is at the last character — `column == context.length()` — the caret was not rendered. Use `<=` so the caret is shown for the last character too, while still rejecting positions past the end of the context. Closes SpongePowered#625 Signed-off-by: 付典 <fudianchn@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
ParsingException.getMessage()renders a caret (^) under the error column, but guards it withcolumn < context.length().columnis 1-indexed (the caret is drawn at positioncolumn - 1), so when the error is on the last character —column == context.length()— the caret is dropped (#625).Fix
<=renders the caret for the last character (at positioncolumn - 1), while still rejecting positions past the end.Verification
The caret logic in isolation (the exact branch from
getMessage):Added
ParsingExceptionTest(caretRenderedForLastColumn/caretNotRenderedBeyondContext) — the repo's Gradle build was too heavy to run locally, but the caret logic is verified above and the test codifies it for CI.Closes #625