Skip to content

Go to definition fails on the last character of a reference #3308

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

Open
vinistock opened this issue Mar 17, 2025 · 1 comment
Open

Go to definition fails on the last character of a reference #3308

vinistock opened this issue Mar 17, 2025 · 1 comment
Labels
bug Something isn't working help-wanted Extra attention is needed pinned This issue or pull request is pinned and won't be marked as stale server This pull request should be included in the server gem's release notes

Comments

@vinistock
Copy link
Member

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:

  1. 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.

  1. 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
@vinistock vinistock added bug Something isn't working help-wanted Extra attention is needed pinned This issue or pull request is pinned and won't be marked as stale server This pull request should be included in the server gem's release notes labels Mar 17, 2025
@ZainIftikhar7vals
Copy link

Hi @vinistock , i want to work on this issue

Can you please explain how do I verify that solution 1 is not causing any weirdness in existing features.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help-wanted Extra attention is needed pinned This issue or pull request is pinned and won't be marked as stale server This pull request should be included in the server gem's release notes
Projects
None yet
Development

No branches or pull requests

2 participants