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
Definition support for autoloaded constants #1995
base: main
Are you sure you want to change the base?
Definition support for autoloaded constants #1995
Conversation
I have signed the CLA! |
I have signed the CLA! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking great! There's only one piece missing. To improve the precision of where you can cmd click, you need to add one extra check to this condition
target.name != :autoload
lib/ruby_lsp/listeners/definition.rb
Outdated
if name != :autoload | ||
return | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is already being checked where the method is invoked, so this can be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it
lib/ruby_lsp/listeners/definition.rb
Outdated
arguments = node.arguments # should be 'ArgumentsNode' | ||
return unless arguments.is_a?(Prism::ArgumentsNode) | ||
|
||
symbol = arguments.arguments[0] # should be 'SymbolNode' | ||
return unless symbol.is_a?(Prism::SymbolNode) | ||
|
||
find_in_index(symbol.value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
arguments = node.arguments # should be 'ArgumentsNode' | |
return unless arguments.is_a?(Prism::ArgumentsNode) | |
symbol = arguments.arguments[0] # should be 'SymbolNode' | |
return unless symbol.is_a?(Prism::SymbolNode) | |
find_in_index(symbol.value) | |
arguments = node.arguments&.arguments | |
return unless arguments | |
value = arguments.first&.value | |
return unless value | |
find_in_index(value) |
end | ||
end | ||
|
||
def test_jumping_to_autoload_definition_with_two_definition |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Multiple declarations for the same constant is already handled and tested by the index, so I'd remove this test.
connected another email with the CLA |
I have signed the CLA! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a rebase, otherwise looks ready to go.
lib/ruby_lsp/listeners/definition.rb
Outdated
@@ -145,6 +147,18 @@ def handle_require_definition(node) | |||
end | |||
end | |||
|
|||
sig { params(node: Prism::CallNode).void } | |||
def handle_autoload_definition(node) | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove the blank line here.
server.process_message( | ||
id: 1, | ||
method: "textDocument/definition", | ||
params: { textDocument: { uri: uri }, position: { character: 3, line: 3 } }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once #2036 is solved, the tests can be updated so that the position corresponds to :Bar
rather than autoload
.
There is one typecheck failure, it may indicate a missing nil check. |
|
…n.rb#handle_autoload_definition
Motivation
There are an issue calling for complete this function (#1893).
Implementation
autoload
argument is aPrism::CallNode
which has name:autoload
. I createhandle_autoload_definition
method and add it toon_call_node_enter
method in 'lib/ruby_lsp/listeners/definition.rb'. Then inhandle_autoload_definition
method, we can use the name of the constant in thePrism::SymbolNode
under thePrism::CallNode
and pass the name tofind_in_index
, which can create the response of jumping.Automated Tests
Completed automated tests in
test/requests/definition_expectations_test.rb
, includingtest_jumping_to_autoload_definition_when_declaration_exists
,test_jumping_to_autoload_definition_with_two_definition
andtest_does_nothing_when_autoload_declaration_does_not_exist
Manual Tests
.rb
file which hasautoload
arguments.autoload
arguments, press ctrl & click it