Fix byte/character offset confusion in formatter for multi-byte UTF-8 #105
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.