Skip to content

fix(vscode): should compute range correctly with chinese characters#733

Merged
9aoy merged 3 commits intomainfrom
fix/chinese-char
Dec 4, 2025
Merged

fix(vscode): should compute range correctly with chinese characters#733
9aoy merged 3 commits intomainfrom
fix/chinese-char

Conversation

@9aoy
Copy link
Copy Markdown
Collaborator

@9aoy 9aoy commented Dec 4, 2025

Summary

fix wrong position when code with chinese characters.

image

Related Links

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copilot AI review requested due to automatic review settings December 4, 2025 03:57
@netlify
Copy link
Copy Markdown

netlify bot commented Dec 4, 2025

Deploy Preview for rstest-dev ready!

Name Link
🔨 Latest commit 28823fd
🔍 Latest deploy log https://app.netlify.com/projects/rstest-dev/deploys/6931082b1a3d8d0008ca2bba
😎 Deploy Preview https://deploy-preview-733--rstest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a bug in the VSCode extension where range/position calculations were incorrect when source code contained multi-byte UTF-8 characters (such as Chinese characters). The SWC parser returns byte offsets, but the previous implementation incorrectly treated them as character offsets, causing misalignment when multi-byte characters were present.

Key Changes:

  • Modified spanToRange function to convert SWC's byte offsets to character indices using Buffer operations
  • Added defensive programming with Math.max(0, ...) and optional chaining for edge cases
  • Added comprehensive test coverage with a test file containing Chinese characters

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
packages/vscode/src/parserTest.ts Implements byte-to-character conversion using Buffer to correctly handle multi-byte UTF-8 characters when calculating ranges
packages/vscode/tests/unit/test.txt Test fixture containing a long string of Chinese characters to trigger the multi-byte character bug
packages/vscode/tests/unit/parse.test.ts New test case that verifies range calculation works correctly with multi-byte characters

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

9aoy and others added 2 commits December 4, 2025 12:03
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@9aoy 9aoy merged commit 9087bb8 into main Dec 4, 2025
16 checks passed
@9aoy 9aoy deleted the fix/chinese-char branch December 4, 2025 06:06
@9aoy 9aoy mentioned this pull request Dec 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants