Go to definition fails on the last character of a reference
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 45/100
Research direction
Start at lib/ruby_lsp/ruby_document.rb around the linked range check, then trace how go-to-definition locates references. Reproduce the Foo and Bar.something cursor positions and evaluate the inclusive-range option against existing behavior; done means both immediately-after-reference cases resolve without breaking other features.
Written by the indexing model from the issue text.
Description
Currently, we fail to locate the target for a go to definition request if the cursor is immediately after the reference the user is trying to jump to. For example:
Foo
# ^ cursor position
Bar.something
# ^ cursor position
Initially, I thought this implementation was correct, since the reference's location given to us by Prism really does not cover that one extra character. The cursor is in the next immediate character, not on top of the reference.
However, I checked what other LSPs do and apparently they do catch the reference even if the cursor is one character beyond.
I think we have two possible solutions for this:
- The more general option is to consider an inclusive range here. In other words, just change that line to be
# Remove one of the dots to make the range inclusive
next unless (loc_start_offset..loc_end_offset).cover?(char_position)
If this works properly, without causing any weirdness in one of our features, then this is the appropriate solution.
- If 1 is not viable, then we should perform some sort of off-by-one correction in the definition request when locating targets. This is not ideal, but would fix the scenario
- Dominant language
- Ruby
- Stars
- 2k
- Forks
- 281
- Avg merge
- 1h 47m
- Merged PRs (30d)
- 8
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Shopify/ruby-lsp
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
bug help-wanted pinned
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
bug pinned
Difficulty 4/5 3-5 days Newbie friendliness 45/100
-
bug
Difficulty 4/5 3-5 days Newbie friendliness 68/100
-
bug
Difficulty 4/5 3-5 days Newbie friendliness 35/100
All issues in Shopify/ruby-lsp
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
TheOdinProject/curriculum#31417 · 2 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
glossarist/glossarist-ruby#238 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
palladius/rails8-app-on-gcp#145 ·