Shopify / ruby-lsp

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

Add Basic RBS Support #2775

Open andyw8 opened 3 days ago

andyw8 commented 3 days ago

We rely on RBS for features such as documentation and completion for Ruby's own API.

For example, in VS Code, if you right-click on String.pp and choose "Go to Definition", the editor will show results for kernel.rbs and string.rbs.

But if you open that file, you'll notice there is no syntax highlighting, and no other Ruby LSP features are available.

We can add some improvements. These will work similar to the corresponding Ruby features, but since the RBS syntax is simpler, they should be much easier to implement.

(For now we are focusing on reading/navigation RBS, rather than writing it.)

Grammar file

We can base this off the existing VS Code extension for RBS: https://github.com/soutaro/vscode-rbs-syntax/blob/master/syntaxes/rbs.tmLanguage.json (or perhaps this).

We can also add tests, similar to the tests we have for Ruby grammar here.

Go To Definition

For an RBS signature which references another type, we can implement Go To Definition to provide easy navigation.

Hover

Hovering over a type can show any documentation comments.

DocumentSymbol

Similar to what we do for Ruby code, we can implement DocumentSymbol for RBS to power features such as Outline and Go To Symbol.


(this issue is a subset of https://github.com/Shopify/ruby-lsp/issues/1206)

ybiquitous commented 2 days ago

Hi, this effort should be great for so many Rubyists! 👏🏼

JFYI, the grammar file in soutaro/vscode-rbs-syntax is also used by GitHub Linguist: