Skip to content

Conversation

tk0miya
Copy link
Collaborator

@tk0miya tk0miya commented Aug 7, 2025

To make RBS generation faster to extract signatures from the Ruby on
Rails application, this provides the rbs_rails LSP server. It generates
signatures on demand if the IDE lets the rbs_rails LSP server know the
changes to Ruby files.

It preloads the Rails application on start and reloads it when the
source code is changed. It improves the performance of signature
generation rather than running the rbs_rails command

This is a demo movie for this LSP server. I used my RBS helper extension to invoke the server.

The types for models are updated automatically and seamlessly upon editing, database migration, and other similar events.

2025-08-23.17.13.49.mov

Note: this contains #345

@tk0miya tk0miya force-pushed the cli_server branch 3 times, most recently from 312eeab to 4daefc4 Compare August 8, 2025 18:21
@tk0miya tk0miya force-pushed the cli_server branch 5 times, most recently from 6f8600f to 0e049fe Compare August 23, 2025 16:31
Comment on lines 132 to 133
sig = RbsRails::ActiveRecord.class_to_rbs(klass)
rbs_path.write sig
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type signature should be rewritten only if its content has been changed. At present, the reloading cost of Steep is high. It would be better not to change its timestamp if nothing changed.

At present, steep detect the file change via its timestamp.  To avoid
unnecessary type check, this adds FileWriter class which updates the RBS
file only if its content has changed.
So far, our testcases build RBS signatures from scratch every time.  It
is slow and unnecessary.

This introduces a mechanism to share the built signatures across tests.

Before:

```
Finished in 99.189478s, 0.2016 runs/s, 0.1815 assertions/s.

20 runs, 18 assertions, 0 failures, 0 errors, 0 skips
```

After:

```
Finished in 25.321047s, 0.7899 runs/s, 0.7109 assertions/s.

20 runs, 18 assertions, 0 failures, 0 errors, 0 skips
```
ActiveRecord::* and ActiveStorage::* are parts of Ruby on Rails, and
their types are distributed on the gem_rbs_collection repo.  Therefore,
there is no reason to generate types for them.
As a preparation for LSP server, this integrates model_dependencies.rbs
to each model signatures.

With this change, the signature of dependencies will be separated to the
each RBS file of the model.  It allows to rbs_rails to generate
signatures for models one by one, not only the whole of application.  It
also helps the LSP server generate signatures on the fly.
To make RBS generation faster to extract signatures from the Ruby on
Rails application, this provides the rbs_rails LSP server.  It generates
signatures on demand if the IDE lets the rbs_rails LSP server know the
changes to Ruby files.

It preloads the Rails application on start and reloads it when the
source code is changed. It improves the performance of signature
generation rather than running the rbs_rails command
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant