Handle surrogate pair when converting from LSP encoding#1785
Open
bullno1 wants to merge 2 commits intoycm-core:masterfrom
Open
Handle surrogate pair when converting from LSP encoding#1785bullno1 wants to merge 2 commits intoycm-core:masterfrom
bullno1 wants to merge 2 commits intoycm-core:masterfrom
Conversation
1c73ef0 to
8fbddc5
Compare
puremourning
approved these changes
Jun 6, 2025
Member
puremourning
left a comment
There was a problem hiding this comment.
thanks!
Reviewed 2 of 2 files at r1, all commit messages.
Reviewable status: 1 of 2 LGTMs obtained (waiting on @bullno1)
Member
|
@Mergifyio rebase |
Contributor
✅ Branch has been successfully rebased |
8fbddc5 to
ecd1bb8
Compare
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.
The generic LSP completer adds 1 to the code unit position before conversion to get a 1-based index:
ycmd/ycmd/completers/language_server/language_server_completer.py
Lines 3489 to 3490 in a51329a
However, this is problematic when the original index is pointing at a surrogate pair.
For example: given the string:
😊, the language server sends index 0.Adding 1 will point it to the low surrogate and the following conversion will fail with a
UnicodeError:ycmd/ycmd/completers/language_server/language_server_protocol.py
Lines 826 to 827 in a51329a
This is because the surrogate pair is sliced in half.
What this PR does is checking whether the high byte at the offset is a low surrogate and advance the offset further to skip the entire pair.
This only happens for positions sent from the language server so it is not a reversible conversion.
I added a separate test case from
test_CodepointsToUTF16CodeUnitsAndReverseThis change is