Ruby LSP Rails is a Ruby LSP addon for extra Rails editor features, such as:
- Displaying an ActiveRecord model's database columns and types when hovering over it
- Running tests and debugging tests through the terminal or the editor's UI
To install, add the following line to your application's Gemfile:
# Gemfile
group :development do
gem "ruby-lsp-rails"
end
Some features rely on server introspection, and use a Rack server which is automatically mounted by using a Railtie.
For applications with specialized routing requirements, such as custom sharding, this may not be compatible. It can be disabled with:
# config/environments/development.rb
Rails.application.configure do
# ...
config.ruby_lsp_rails.server = false
# ...
end
- Start your Rails server
- Hover over an ActiveRecord model to see its details
Nested models (e.g. Admin::User
) are not yet supported.
See the documentation for more in-depth details about the supported features.
- Open a test which inherits from
ActiveSupport::TestCase
or one of its descendants, such asActionDispatch::IntegrationTest
. - Click on the "Run", "Run in Terminal" or "Debug" code lens which appears above the test class, or an individual test.
Note: When using the Test Explorer view, if your code contains a statement to pause execution (e.g. debugger
) it will
cause the test runner to hang.
This gem consists of two components that enable enhanced Rails functionality in the editor:
- A Rack app that automatically exposes APIs when Rails server is running
- A Ruby LSP addon that connects to the exposed APIs to fetch runtime information from the Rails server
This is why the Rails server needs to be running for some features to work.
Note
There is no need to restart the Ruby LSP every time the Rails server is booted. If the server is shut down, the extra features will temporarily disappear and reappear once the server is running again.
Bug reports and pull requests are welcome on GitHub at https://github.com/Shopify/ruby-lsp-rails. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
The gem is available as open source under the terms of the MIT License.