Problem
In spx-gui/src/components/editor/code-editor/xgo-code-editor/diagnostics.ts, the adaptLSDiagnosticRange function is supposed to expand a zero-length diagnostic range so that it can be displayed as an inline decoration. However, when the diagnostic position is at or near EOF, the expansion logic fails:
// If no non-newline character is found forward, fall back to backward scan:
for (let i = offsetStart; i >= 0; i--) {
if (code[i] !== '\n') {
offsetStart = i
break
}
}
When offsetStart === code.length (EOF), the backward scan starts at index code.length, but code[code.length] is undefined (not '\n'), so offsetStart = i is set to code.length — leaving start === end. The expanded range is still empty.
Expected Behavior
adaptLSDiagnosticRange should always return a non-empty range (i.e. start !== end) when given a zero-length input range, including at EOF.
Suggested Fix
- Start the backward scan from
offsetStart - 1 (not offsetStart) to avoid the off-by-one issue.
- When no non-newline character exists anywhere (e.g. file is all newlines or empty), ensure
offsetEnd is advanced to at least offsetStart + 1 as a last resort.
Location
spx-gui/src/components/editor/code-editor/xgo-code-editor/diagnostics.ts — adaptLSDiagnosticRange method
Notes
This bug is pre-existing (not introduced by PR #2858). Tracked here per review comment in that PR.
Problem
In
spx-gui/src/components/editor/code-editor/xgo-code-editor/diagnostics.ts, theadaptLSDiagnosticRangefunction is supposed to expand a zero-length diagnostic range so that it can be displayed as an inline decoration. However, when the diagnostic position is at or near EOF, the expansion logic fails:When
offsetStart === code.length(EOF), the backward scan starts at indexcode.length, butcode[code.length]isundefined(not'\n'), sooffsetStart = iis set tocode.length— leavingstart === end. The expanded range is still empty.Expected Behavior
adaptLSDiagnosticRangeshould always return a non-empty range (i.e.start !== end) when given a zero-length input range, including at EOF.Suggested Fix
offsetStart - 1(notoffsetStart) to avoid the off-by-one issue.offsetEndis advanced to at leastoffsetStart + 1as a last resort.Location
spx-gui/src/components/editor/code-editor/xgo-code-editor/diagnostics.ts—adaptLSDiagnosticRangemethodNotes
This bug is pre-existing (not introduced by PR #2858). Tracked here per review comment in that PR.