Positions are UTF-8 byte offsets while positionEncoding says utf-16

Đang mở
#4,281 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
45/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
ruby

Hướng nghiên cứu

Start from the InitializeResult where positionEncoding is advertised, then trace how textDocument/references, definition, hover and diagnostics convert character offsets; compare that path with the ranged didChange sync path that already handles UTF-16. Reproduce with the a.rb snippet and check the call site on line 5 at UTF-16 column 19 versus UTF-8 byte column 22. Done means those requests and diagnostics use UTF-16 code units, with regression tests covering non-ASCII text before a token.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Version: ruby-lsp 0.26.11, Ruby 4.0.3, Linux x86_64, a plain stdio LSP client (not VS Code).

What happens. The server's InitializeResult advertises positionEncoding: "utf-16", whether the
client offers general.positionEncodings: ["utf-16"] or no positionEncodings at all. On a line with
non-ASCII text before a token, the character it returns and reads is a UTF-8 byte offset, not a
UTF-16 code-unit offset.

Repro. a.rb:

class Foo
  def self.helper
    1
  end
  def self.run
    s = "é😀"; Foo.helper
  end
end

On line 5, helper starts at UTF-16 column 19 (UTF-8 byte 22, code point 18).

  • textDocument/references at the definition (line 1, character 11) returns the call site at
    line 5, character 22.
  • textDocument/definition and textDocument/hover at line 5, character 20 (inside helper
    in UTF-16) return nothing. At character 23 (inside it in UTF-8 bytes), definition goes to line 1
    and hover shows helper().
  • Diagnostics on such lines are also placed at byte offsets.

Expected. UTF-16 code units, as advertised, or advertising utf-8 when the client offers it.

Note. A whole-document ranged didChange whose end is computed in UTF-16 is applied
correctly, so the document sync path seems to convert; requests and responses don't.

Possibly related: #4180 (completion after Unicode in an interpolated string) and #4094 (RuboCop
quickfix with multi-byte characters).

Ngôn ngữ chính
Ruby
Star
2k
Fork
300
Merge trung bình
2 giờ 54 phút
Pull request đã merge (30 ngày)
9

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của Shopify/ruby-lsp

Tất cả issue của Shopify/ruby-lsp

Issue tương tự

Thêm issue về Ruby

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.