Ruby LSP (VS Code extension)The Ruby LSP is an extension that provides performant rich features for Ruby. It connects to the ruby-lsp language server gem to analyze Ruby code and enhance the user experience. Want to discuss Ruby developer experience? Consider joining the public Ruby DX Slack workspace. UsageSearch for By default, the Ruby LSP will generate a FeaturesThe Ruby LSP features include
Adding method support for definition, completion, hover and workspace symbol is planned, but not yet completed. See complete information about features in the ruby-lsp server documentation. If you experience issues using the extension, please see the troubleshooting guide. CommandsAvailable commands are listed below and can always be found by searching for the
SnippetsThis extension provides convenience snippets for common Ruby constructs, such as blocks, classes, methods or even unit test boilerplates. Find the full list here. ConfigurationEnable or disable featuresThe Ruby LSP allows disabling specific features. To do so, open the
language status center right next to the language mode Ruby and select It's also possible to configure with more granularity code lens and inlay hint features, see the Ruby LSP server documentation. Ruby version managersTo boot the server properly, the Ruby LSP uses a version manager to activate the right environment variables that point Bundler to the Ruby and gem paths. This is especially necessary when switching between projects that use different Ruby versions - since those paths change and need to be reactivated. By default, the Ruby LSP will attempt to automatically determine which version manager it should use, checking which
ones are available (
To make sure that the Ruby LSP can find the version manager scripts, make sure that they are loaded in the shell's configuration script (e.g.: ~/.bashrc, ~/.zshrc) and that the SHELL environment variable is set and pointing to the default shell.
Configuring a formatterThe tool to be used for formatting files can be configured with the following setting.
Ruby version requirementBy default, the Ruby LSP uses the current project's Ruby version and bundle. This allows the LSP to index the correct gem versions, and to ensure formatting behavior is consistent with CI. The Ruby LSP and its main dependency Prism (the new Ruby parser) both follow the same policy, which is to support only Ruby versions that are not beyond their end-of-life. If you're working on a project with an older Ruby version, it might be possible to install older versions of the server gem to get support for older rubies, but that might also involve using older versions of the VS Code extension - since some functionality requires implementations in both client and server. The other alternative is to use a custom Gemfile separate from the project with a different Ruby version. Notice that certain functionality may be degraded or require manual configuration, since the Ruby LSP will not be able to inspect the project's real bundle to discover dependencies. Please see the instructions below. Using a custom GemfileIf you are working on a project using an older version of Ruby not supported by Ruby LSP, then you may specify a
separate Note: when using this, gems will not be installed automatically and neither will Create a directory to store the custom bundle outside of the project that uses the old Ruby version. Inside that
directory, add your preferred version manager configuration to select a supported Ruby version. For example, if using
Create a
Run
Configuring VS Code debuggerTo configure the VS Code debugger, you can use the "Debug: Add configuration..." command to create a This command would generate the following configuration:
Debugging live processesInstead of launching a process to debug every time, you may want to attach the VS Code debugger to an existing process, such as a Rails server. Follow these instructions to do so. Install Run your application with the debugger attached, so that the extension can connect to it.
For better integrated rails tests support also install VS Code configurationsIn addition to the Ruby LSP's own configuration, there are some VS Code settings that may need to be changed to get the most of the Ruby LSP. These settings are not specific to the Ruby LSP, but they impact all language servers and take precedence over any other configurations. These are the settings that may impact the Ruby LSP's behavior and their explanations.
Multi-root workspacesThe Ruby LSP supports multi-root workspaces by spawning a separate language server for each one of them. This strategy is preferred over a single language server that supports multiple workspaces because each workspace could be using a different Ruby version and completely different gems - which would be impossible to support in a single Ruby process. Please see the VS Code workspaces documentation on how to configure the editor for multi-root workspaces. The Ruby LSP should work properly out of the box as long as the workspace configuration is following the guidelines. Monorepos containing multiple workspacesA common setup is using a monorepo with directories for sub-projects. For example:
This situation also falls under the category of multi-root workspaces. In this context, Developing on containersThe Ruby LSP is a detached language server, which means it's a background process that runs separately from the VS Code instance. To provide its functionality, the Ruby LSP must be running in the same place where your project files exist and dependencies are installed. VS Code supports connecting to containers out of the box, which makes all editor features work seamlessly. That includes language servers, the integrated terminal, etc. The VS Code documentation has instructions on how to develop on containers locally or remotely. Please check the following resources before opening an issue: Please note that only Docker is officially supported as a backend by the Dev Container extension. 1 TelemetryOn its own, the Ruby LSP does not collect any telemetry by default, but it does support hooking up to a private metrics service if desired. In order to receive metrics requests, a private plugin must export the Fields included by default are defined in For example,
FormattingWhen If the bundle has a direct dependency on a supported formatter, such as ContributingBug reports and pull requests are welcome on GitHub at https://github.com/Shopify/vscode-ruby-lsp. 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. Before contributing, please make sure to sign the Contributor License Agreement. DebuggingInteractive debugging works for both running the extension or tests. In the debug panel, select whether to run the extension in development mode or run tests, set up some breakpoints and start with F5. Tracing LSP requests and responsesLSP server tracing (logging) can be controlled through the Possible values are:
Debugging the server using VS CodeThe
LicenseThis extension is available as open source under the terms of the MIT License. |