Closed NotFounds closed 2 weeks ago
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 Thank you for your review! As you pointed out, the changes can be broken down into multiple tasks. I'll close this Pull Request for now and focus on fixing the handling of multibyte characters first.
I opened a new PullRequest. https://github.com/Shopify/ruby-lsp/pull/2051
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 https://github.com/ruby/prism/pull/2406.Prism::Location
to RubyIndexer::Location
by https://github.com/Shopify/ruby-lsp/pull/1917, a new field has been added to RubyIndexer::Location
.Automated Tests
I added a simple expectation test for the definition.
Manual Tests