{{ message }}
Repository navigation
fix(lsp): do not panic on positions that are out of range - #1267
Merged
Merged
Conversation
A position past the end of a line is valid in the language server protocol and means the end of that line, but it was used as is. That could make the start of a range after its end, which panicked, or produce an offset past the end of the text or in the middle of a character, which panicked or corrupted the stored text when applying an incremental change. Positions are now clamped to the end of their line, a position past the last line is the end of the text, a position in the middle of a surrogate pair is the start of the character, and a range whose start is after its end is an error instead of a panic.
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.

LineIndex::offsetused a position's character as is, without clamping it to the line. The language server protocol says a character past the end of a line means the end of that line, so these are valid requests that the server mishandled:"ab\ncd"with the range(0, 100)-(1, 0)made the start offset (100) greater than the end (3) and hit the assertion inTextRange::new, which panics.String::replace_rangewhen the offset was past the end of the text.Now:
LineIndex::offsetno longer returns aResultbecause it can't fail anymore.