Improving the Developer Experience with the Ruby LSP

The Ruby LSP is a new language server built at Shopify that makes coding in Ruby even better by providing extra Ruby features for any editor that has a client layer for the LSP. In this article, we’ll cover how we built the Ruby LSP, the features included within it, and how you can install it.

Vinicius Stock
17 min readbeginner
--
View Original

Overview

The article discusses the development and features of the Ruby LSP (Language Server Protocol), aimed at enhancing the developer experience in Ruby programming. It highlights the importance of tooling in modern programming languages and details how the Ruby LSP improves coding efficiency without requiring type annotations.

What You'll Learn

1

How to install and configure the Ruby LSP in VS Code

2

Why the Ruby LSP is designed to enhance developer experience without typechecking

3

How to implement nonpositional feature requests like Folding Range in Ruby LSP

4

When to use YJIT for performance improvements in Ruby LSP

Prerequisites & Requirements

  • Basic understanding of Ruby programming and LSP concepts
  • Familiarity with VS Code and its extension installation process(optional)

Key Questions Answered

What are the key features of the Ruby LSP?
The Ruby LSP supports features such as code actions, diagnostics, document highlight, document link, document symbol, folding range, formatting, hover, inlay hints, on type formatting, selection ranges, semantic highlighting, and completion. These features enhance the coding experience by providing real-time feedback and assistance.
How does the Ruby LSP handle document synchronization?
The Ruby LSP maintains document synchronization by receiving notifications from the editor about file changes, such as when a document is opened, modified, or closed. This allows the server to keep an accurate representation of the current state of the files being worked on.
What is the significance of YJIT in the Ruby LSP?
YJIT (Yet another Just-in-Time compiler) significantly boosts the performance of the Ruby LSP by optimizing the execution of Ruby code. When using Ruby 3.2 compiled with YJIT, the Ruby LSP can leverage this for faster parsing and analysis of Ruby files.
How does the Ruby LSP differ from other Ruby language servers?
Unlike other Ruby language servers like Sorbet and Solargraph, the Ruby LSP does not require typechecking or type annotations, aiming instead to provide accurate features based on the existing Ruby code. This makes it more accessible for developers who prefer not to annotate their code.

Technologies & Tools

Some links below are affiliate links. We may earn a commission if you make a purchase.

Backend
Ruby
The Ruby LSP is implemented entirely in Ruby, allowing for rapid feature development and integration with Ruby's own parser.
Frontend
Vs Code
The Ruby LSP can be integrated with any editor that supports LSP, but specific instructions are provided for VS Code.

Key Actionable Insights

1
Integrating the Ruby LSP into your development environment can significantly enhance your coding efficiency by providing real-time feedback and features like code actions and diagnostics.
By leveraging the Ruby LSP, developers can focus more on writing business logic rather than dealing with language constraints, which aligns with Ruby's goal of improving developer happiness.
2
Utilizing YJIT when running Ruby LSP can lead to noticeable performance improvements, especially in larger codebases.
If you're working with Ruby 3.2, enabling YJIT can help reduce latency in editor interactions, making the development experience smoother and more responsive.
3
Understanding the document synchronization process is crucial for effectively using the Ruby LSP.
By knowing how the Ruby LSP tracks changes in open documents, developers can better anticipate how their coding actions will be reflected in the editor, leading to a more seamless experience.

Common Pitfalls

1
Failing to properly configure the Ruby LSP extension can lead to a lack of features or errors during development.
Ensure that the Ruby version manager is correctly set up and that the ruby-lsp gem is included in your project's bundle to avoid issues.

Related Concepts

Language Server Protocol
Ruby On Rails
Performance Optimization Techniques
Yjit