Find references and go-to-definition #3085
Replies: 1 comment
-
Hello!
This is a consequence of the lack of statically discoverable type information and lack of packaging in Ruby. Without type annotations, there are limits to how accurate the analysis can be. And the lack of packaging makes the analysis expensive, further increasing the importance of annotations to achieve adequate performance. I tried to capture the main reasons in this discussion. We are always trying to improve, but the best way to achieve high accuracy for static analysis is adopting a type system.
Sorbet is a type system, type checker and language server. It has all 3 components in it, including runtime type checking.
The type checker needs type annotations to improve the accuracy of the analysis and guarantee performance (like eliminating cross-method analysis with method signatures). Any type checker would require annotations to be added. The distinction is in how the annotations are added. Since Ruby did not want to accept syntax changes for typing, there were only 3 directions for typing to evolve:
Sorbet went with a mix between the first and the third option. You can add a lot of type information in separate RBI files, but it also allows you to add inline annotations. Since those annotations are in the middle of the Ruby code, then they have to be valid Ruby too.
If you want go to definition and find references information, Sorbet can try to return those via its language server, but the accuracy will always be limited based on the amount of type information available. For example, if the codebase has zero method signatures or doesn't use Sorbet at all, then every method is untyped and the analysis will be very limited. |
Beta Was this translation helpful? Give feedback.
-
Hi, I'm building a language server container lsproxy, and would like to add Ruby support.
The main use case is for code navigation for AI purposes, so the most important functionality is GoToDefinition and FindReferences. I know that Ruby is a pain to work with and none of the language servers do this that well.
It seems like Ruby LSP is in the same ballpark as solargraph for these functions, but you guys are continuing to make it better?
Sorbet seems to be primarily a type system and actually requires changing the code to support it? So I'd imagine that doesn't make sense for this application given we need to make this work for codebases we've never seen and cannot change?
Thanks for the help and looking forward to working with y'all!
Beta Was this translation helpful? Give feedback.
All reactions