Repository navigation
Conversation
Go to definition on the name of a method declaration returned nothing. Class and module names already resolve to their own declaration, which lets editors switch to their alternative action, such as VS Code showing references. Methods now behave the same way, except on typed true or higher, where Sorbet handles method definitions.
Author
|
I have signed the CLA! |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Go to definition on the name of a method declaration (
def foo) returns nothing. On a class or module name (class Foo) it returns the declaration itself, which editors rely on: when the only definition is the one under the cursor, VS Code runs its alternative command, Go to References by default. So Cmd/Ctrl+click on a class name shows its usages, but on a method name it shows "No definition found", and finding a method's usages from its declaration needs a separate shortcut.Implementation
Requests::DefinitionacceptsPrism::DefNodeas a target, but only when the cursor is on the method's name (name_loc). Thedefkeyword, parameters and body still return nothing, handled inposition_outside_target?like the other targets that usename_loc.Listeners::Definition#on_def_node_enterreturns aLocationLinkto the method itself, withtarget_rangecovering the whole declaration andtarget_selection_rangecovering the name. It is skipped ontyped: trueor higher, as for method calls onself, because Sorbet handles method definitions there.One thing to watch: with
DefNodeamong the located node types, a cursor inside a method body that previously matched no target now locates the enclosingDefNodefirst.position_outside_target?then discards it, so those positions still return nothing. A test covers this.Automated Tests
Added four tests to
test/requests/definition_expectations_test.rb:def self.bar).typed: truefiles, where nothing is returned.The first two fail without the change. RuboCop and
srb tcpass.Manual Tests
defline, or put the cursor on it and press F12.class Foo, which already behaves this way.