Use location links for namespace and method definition response #2206
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
I noticed that we were unable to go to definition for constants that were referenced inside their own declaration. E.g.:
At first, I thought something was wrong with constant resolution, but it was not the case. We were always returning the class' complete location back to the editor (including the body part). This makes the editor consider any attempts to go to definition of the same symbol as a references rather than a definition request.
In reality, we only want the reference request to be invoked if someone CMD clicks the
Foo
declaration, but not a constant reference like the one in line 1.Implementation
The spec provides the location link type to handle situations like these.
Location links allow us to return two locations:
By using location links and passing only the identifier locations for namespaces and methods, then the editor does the right thing and allows us to correctly jump to definition for constant references inside their own declarations.
resolve
more specific to avoid any typing issuesAutomated Tests
I adapted the existing tests, but because this specific scenario requires full interaction with the editor, I could not manage to get a test working properly.
Manual Tests
On main, when you cmd click a constant reference that exists inside its own declaration, the editor will show "no references found for
Foo
" (because we don't implement the references request yet).On this branch, you will jump to the right declaration.