Fix byte/character offset confusion in formatter for multi-byte UTF-8#105
Merged
Fix byte/character offset confusion in formatter for multi-byte UTF-8#105
Conversation
Co-authored-by: asharkhan3101 <140482588+asharkhan3101@users.noreply.github.com>
Co-authored-by: asharkhan3101 <140482588+asharkhan3101@users.noreply.github.com>
Co-authored-by: asharkhan3101 <140482588+asharkhan3101@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix formatting bug creating empty comment lines
Fix byte/character offset confusion in formatter for multi-byte UTF-8
Feb 2, 2026
asharkhan3101
approved these changes
Feb 2, 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.
Formatting proto files with multi-byte UTF-8 characters (Cyrillic, etc.) was non-idempotent, adding empty
//comment lines on each format operation.Root Cause
offset_to_positioninsrc/formatter/clang.rsconverted clang-format's byte offsets to LSP positions using byte arithmetic:This fails for multi-byte UTF-8. Example: byte offset 134 in Cyrillic text → calculated position 119 → should be 77 UTF-16 code units.
Changes
Fixed offset calculation: Count UTF-16 code units from last newline instead of byte arithmetic
Added tests:
test_offset_to_position_cyrillic(unit) andtest_textedit_from_clang_output_cyrillic(integration) with multi-byte UTF-8 inputOriginal prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.