Skip to content

Restore scanner line positions after seeking - #155

Open
Pradeep Ramola (pradeep-ramola) wants to merge 1 commit into
microsoft:mainfrom
pradeep-ramola:fix/scanner-seek-positions
Open

Pradeep Ramola (pradeep-ramola) wants to merge 1 commit into
microsoft:mainfrom
pradeep-ramola:fix/scanner-seek-positions

Conversation

@pradeep-ramola

Copy link
Copy Markdown

Fixes #154.

setPosition() updates the scan offset but leaves the old line-number and line-start state in place. Seeking forward reports line zero for later lines, and rewinding after scanning multiline text can produce negative columns.

Reset the line state alongside the existing token state. For nonzero seeks, build a line-start index lazily and use binary search to locate the target line. The index is reused on later seeks; ordinary sequential scanning does not build one. CRLF pairs remain a single line break, including when seeking between CR and LF.

Added 16 regression/control tests covering forward seeks, rewinds, offset zero, EOF, LF/CRLF/CR, both trivia modes, and single-line and mid-CRLF controls. On unchanged main, 12 new tests fail and four controls pass.

Validation on Windows:

  • npm test with Node 22.23.5: TypeScript compilation, ESLint, and all 104 tests pass.
  • Full compiled test suite with Node 24.16.0: all 104 tests pass.
  • 17,097 additional scanner comparisons: re-seeks match sequential token snapshots, and all offsets in short mixed-line-ending inputs report the expected physical line and column.
  • git diff --check: passes.

No public API, dependency, or changelog changes. Linux and macOS were not tested locally. This does not change the unterminated-comment behavior discussed in #150 or the token-value optimization in #151.

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.

Scanner reports stale line and column positions after setPosition

1 participant