Ruby LSP Integration
Operandi provides a Ruby LSP add-on that enhances your editor experience by informing the language server about methods generated by the arg and output DSL keywords.
Features
When you use the arg or output keywords, Operandi dynamically generates methods at runtime:
class MyService < ApplicationService
arg :user, type: User
output :result, type: Hash
endThis generates the following methods:
user- getter method (returnsUser)user?- predicate method (returns boolean)user=- setter method (private, acceptsUser)result- getter method (returnsHash)result?- predicate method (returns boolean)result=- setter method (private, acceptsHash)
The Ruby LSP add-on teaches the language server about these generated methods, enabling:
Go to Definition - Navigate to the
arg/outputdeclarationCompletion - Autocomplete generated method names
Hover - See information about generated methods, including return types
Signature Help - Get parameter hints for setter methods
Workspace Symbol - Find generated methods in symbol search
Setup
The add-on is automatically discovered by Ruby LSP when Operandi is in your project's dependencies. No additional configuration is required.
Requirements
Ruby LSP
~> 0.26or laterOperandi gem installed in your project
Verification
To verify the add-on is loaded, check the Ruby LSP output in your editor. You should see "Ruby LSP Operandi" listed among the active add-ons.
How It Works
The add-on uses Ruby LSP's indexing enhancement system to register generated methods during code indexing. When the indexer encounters an arg or output call with a symbol argument, it automatically registers the three generated methods (getter, predicate, setter) in the index.
This is a static analysis approach - the add-on analyzes your source code without executing it. This means:
Methods are recognized immediately as you type
No running application is required
Works with any editor that supports Ruby LSP
Type Inference
The add-on extracts type information from the type: option and includes it as YARD-style documentation comments. This enables hover information to display return types for generated methods.
Simple Ruby Types
Namespaced Types
Sorbet Runtime Types
Sorbet runtime types are resolved to their underlying Ruby types:
T::Boolean
TrueClass | FalseClass
T.nilable(String)
String | NilClass
T::Array[String]
Array
T::Hash[Symbol, String]
Hash
T.any(String, Integer)
String | Integer
Custom Type Mappings
You can add custom type mappings through the Operandi configuration:
Custom mappings allow you to:
Add mappings for your own custom types
Override default mappings if needed
Support domain-specific type modules
Limitations
Only
argandoutputdeclarations with a symbol as the first argument are recognizedThe add-on cannot detect dynamically computed argument names (e.g.,
arg some_variable)Inherited arguments/outputs from parent classes are not automatically discovered
Parameterized types like
T::Array[String]resolve to the container type (Array), not the full generic type
What's Next?
Learn more about other integrations:
RuboCop Integration - Static analysis cops for services
Testing - Testing your services with RSpec matchers
Last updated