ruby / ruby/rbs

Position of RBS::Location should be byte length

Open
#1,814 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
2.2k
Forks
256
Avg merge
6d 17h
Merged PRs (30d)
37

Description

I'm developing a tool using RBS.
And I'm trying to load RBS files using RBS::MethodType#location and display them with colors.

During development, a problem occurred where the display is off by one character only in core/math.rbs.

In core/math.rbs, the character π is used in the documentation, which is a 2 byte character.

Upon investigation, it appears that the positions in Location are recorded not in byte size but in the number of UTF-8 characters.

# Whether the comment is `π` or `p`, the class location has not changed.

::RBS::Parser.parse_signature("#π\nclass Foo\nend")[2][0].location.start_pos
#=> 3
::RBS::Parser.parse_signature("#p\nclass Foo\nend")[2][0].location.start_pos
#=> 3

Recording the position in bytesize would make it more convenient for reading with methods like IO#read, so I believe it should be recorded in bytesize.

What do you think?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with RBS::Location and the positions returned by RBS::Parser.parse_signature, using the core/math.rbs example with π as the reproduction case. Check how location offsets are consumed with IO#read; done means positions account for UTF-8 byte length and the π/p comparison behaves as intended.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.