Shopify / ruby-lsp

An opinionated language server for Ruby
https://shopify.github.io/ruby-lsp/
MIT License
1.33k stars 118 forks source link

Definition support for autoloaded constants #1995

Open Super-Xray opened 2 weeks ago

Super-Xray commented 2 weeks ago

Motivation

There are an issue calling for complete this function (https://github.com/Shopify/ruby-lsp/issues/1893).

Implementation

autoload argument is a Prism::CallNode which has name :autoload. I create handle_autoload_definition method and add it to on_call_node_enter method in 'lib/ruby_lsp/listeners/definition.rb'. Then in handle_autoload_definition method, we can use the name of the constant in the Prism::SymbolNode under the Prism::CallNode and pass the name to find_in_index, which can create the response of jumping.

Automated Tests

Completed automated tests in test/requests/definition_expectations_test.rb, including test_jumping_to_autoload_definition_when_declaration_exists, test_jumping_to_autoload_definition_with_two_definition and test_does_nothing_when_autoload_declaration_does_not_exist

Manual Tests

  1. Start the extension on this branch
  2. open an .rb file which has autoload arguments.
  3. move the cursor above the autoload arguments, press ctrl & click it
  4. sometimes it doesn't work in original file of ruby-lsp since it's a sorbet project
Super-Xray commented 2 weeks ago

I have signed the CLA!

Super-Xray commented 2 weeks ago

I have signed the CLA!

Super-Xray commented 1 week ago

connected another email with the CLA

Super-Xray commented 1 week ago

I have signed the CLA!

andyw8 commented 6 days ago

There is one typecheck failure, it may indicate a missing nil check.

Super-Xray commented 4 days ago

There is one typecheck failure, it may indicate a missing nil check. image @andyw8 Did you mean this error? I have fixed it.