Fix Unicode offsets in completion replacement ranges - #4188
Open
rubemoon wants to merge 1 commit into
Open
Conversation
Author
|
I have signed the CLA! |
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.
Motivation
Closes #4180
Completion replacement ranges are incorrect when Unicode characters appear before the completion target on the same line.
For example:
When completing
tetotest, the replacement range was returned as characters13..15instead of11..13, causing the resulting text to be corrupted.Implementation
Pass the document's negotiated code units cache to the completion listener and use it when converting Prism locations into LSP ranges.
A completion-specific
range_from_prism_locationhelper now usescached_start_code_units_columnandcached_end_code_units_columnso replacement ranges respect the position encoding negotiated with the client.The shared
Common#range_from_locationhelper remains unchanged, avoiding changes to other LSP features that also use that helper.The conversion is applied consistently to Prism-based replacement ranges used by completion items.
Automated Tests
Added a regression test that reproduces the issue with a Unicode character before a local variable completion target.
Validation performed:
bundle exec rubocopbundle exec srb tcgit diff --checkManual Tests
te.testlocal variable completion.Expected result:
The completion should replace only
te, without overwriting or duplicating surrounding characters.