Skip to content

Render error caret for the last character of the parsing context - #627

Open
fudianchn wants to merge 1 commit into
SpongePowered:trunkfrom
fudianchn:fix-caret-last-column
Open

Render error caret for the last character of the parsing context#627
fudianchn wants to merge 1 commit into
SpongePowered:trunkfrom
fudianchn:fix-caret-last-column

Conversation

@fudianchn

@fudianchn fudianchn commented Aug 9, 2026

Copy link
Copy Markdown

Problem

ParsingException.getMessage() renders a caret (^) under the error column, but guards it with column < context.length(). Because column is 1-indexed (the caret is drawn at position column - 1), the caret is dropped when the error is on the last character, i.e. column == context.length() (#625).

Fix

-            if (this.column >= 0 && this.column < this.context.length()) {
+            if (this.column >= 0 && this.column <= this.context.length()) {

<= renders the caret for the last character (at position column - 1) while still rejecting positions past the end. A short comment notes the 1-indexing so the boundary is not flipped back by mistake.

Verification

The caret branch from getMessage(), with context "hello" (length 5):

column OLD (<) caret? NEW (<=) caret?
5 (== length, last char) no (bug) yes, under the last char
3 (mid) yes yes (no regression)
6 (> length, past end) no no (still rejected)

Added ParsingExceptionTest:

  • caretRenderedForLastColumn asserts the caret is rendered AND aligned under the last character (checks (length - 1) leading spaces, not just that a ^ appears).
  • caretNotRenderedBeyondContext asserts no caret is rendered past the end.

./gradlew :core:checkstyleMain :core:checkstyleTest passes locally.

Closes #625

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. A comment notes the
1-indexing so the boundary is not flipped back by mistake.

Closes SpongePowered#625

Signed-off-by: 付典 <fudianchn@gmail.com>
@fudianchn
fudianchn force-pushed the fix-caret-last-column branch from effbe59 to 15919cd Compare August 13, 2026 04:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ParsingException doesn't allow pointing to the last character

1 participant