-
Notifications
You must be signed in to change notification settings - Fork 155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix go to definition and hover for files containing multibyte characters #2021
Fix go to definition and hover for files containing multibyte characters #2021
Conversation
When a Ruby file contains multibyte characters, the go to definition and hover features do not work correctly. This is because the index building and document referencing logic does not properly handle multibyte characters when calculating offsets. This commit fixes the issue by: •Updating index building to use character offsets instead of byte offsets •Modifying document referencing to properly handle multibyte characters when mapping between positions and offsets •Adding test cases to verify go to definition work with multibyte characters
I have signed the CLA! |
Thank for you the contribution. From a quick read, it seems the PR is doing two main things:
Since UTF-8 is almost always used, is it possible that the first can be addressed without the second? |
@andyw8 |
When a Ruby file contains multibyte characters (like Japanese, Chinese, emoji, etc), the go to definition and hover features do not work correctly. Because the document referencing logic does not properly handle multibyte characters when calculating offsets. This commit fixes the issue by: *Modifying document referencing to properly handle multibyte characters when mapping between positions and offsets *Adding test cases to verify go to definition work with multibyte characters
I opened a new PullRequest. |
Motivation
Closes #1251
When a Ruby file contains multibyte characters (like Japanese, Chinese, emoji, etc), the go to definition and hover features do not work correctly. The definition location or hover documentation will be incorrect.
ref:
This is because the current implementation assumes single-byte characters when calculating offsets during index building and document referencing. We need to properly handle multibyte characters to ensure these features work reliably for all users.
Implementation
RubyLsp::Document
andRubyLsp::Requests::Request
to calculate locations considering multibyte characters. This change utilizes the API implemented in Prism by Add code unit APIs to location ruby/prism#2406.Prism::Location
to RubyIndexer::Location
by Refactor global usage ofPrism::Location
to minimize memory usage #1917, a new field has been added to RubyIndexer::Location
.Automated Tests
I added a simple expectation test for the definition.
Manual Tests