Solargraph

A Ruby Language Server

Plugins

A Solargraph plugin is simply a Ruby gem that implements its own Solargraph features, such as diagnostics reporters and conventions.

A Simple Example

The following code extends Solargraph with a diagnostics reporter that checks for the presence of a frozen_string_literal comment at the top of a Ruby script.

# solargraph-frozen-string.rb

require 'solargraph'

class FrozenStringReporter < Solargraph::Diagnostics::Base
  def diagnose source, _api_map
    return [] if source.code.empty? || source.code.start_with?('# frozen_string_literal:')
    [
        {
            range: Solargraph::Range.from_to(0, 0, 0, source.code.lines[0].length).to_hash,
            severity: Solargraph::Diagnostics::Severities::WARNING,
            source: 'FrozenString',
            message: 'File does not start with frozen_string_literal.'
        }
    ]
  end
end

Solargraph::Diagnostics.register 'frozen-string', FrozenStringReporter

You can use the reporter by creating a gem for it and adding it to .solargraph.yml:

plugins:
- solargraph-frozen-string
reporters:
- frozen-string

When Solargraph loads your project, it will require any gems listed under plugins.