Repository navigation
fix: clamp PositionToOffset.convert on the line just past the end - #2434
Merged
Connor Peet (connor4312) merged 1 commit intoOct 26, 2026
Merged
Connor Peet (connor4312) merged 1 commit into
Connor Peet (connor4312) merged 1 commit into
Conversation
Connor Peet (connor4312)
enabled auto-merge
October 12, 2026 15:40
Dmitriy Vasyura (dmitrivMS)
approved these changes
Oct 26, 2026
Bhavya U (bhavyaus)
approved these changes
Oct 26, 2026
Alexandre Kohler (kwy404)
added a commit
to kwy404/kwy404
that referenced
this pull request
Oct 27, 2026
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.
Root cause:
PositionToOffset.convertinsrc/common/stringUtils.tsis meant to clamp any line past the end of the source tosource.length(the existing test expects line 10 of'\nhello\nworld\n'to give 13). The guard useslineNumber > this.lines.length, so a line number equal tothis.lines.lengthslips through,this.lines[lineNumber]isundefined, and the result isNaN. For examplenew PositionToOffset('hello\nworld').convert(new Base0Position(2, 0))returnsNaNinstead of 11. With aNaNoffset the REPL completions match no node, andextractScopeRenamesassigns it to a sticky regexlastIndex, which reads it as 0 and picks up the identifier at the start of the file.getLineOffsetin the same class already uses>=.Fix: change the guard to
>=, matchinggetLineOffset.Test: added two assertions to the existing
positionToOffsettest insrc/common/stringUtils.test.tsfor the line right after the last one. They fail before the change (expected NaN to equal 11) and pass after.npm run test:unit. The only difference from main is the fixed test (theNodeBinaryProviderfailures are local environment ones and happen on main too).npm run test:types,dprint checkandeslinton the touched files, all clean.