Ruby

Ruby support is available through the Ruby extension.

The Ruby extension also provides support for ERB files.

Choosing a language server

The Ruby extension offers both solargraph and ruby-lsp language server support.

solargraph is enabled by default.

To switch to ruby-lsp, add the following to your settings.json:

{
  "languages": {
    "Ruby": {
      "language_servers": ["ruby-lsp", "!solargraph", "!rubocop", "..."]
    }
  }
}

The Ruby extension also provides support for rubocop language server for offense detection and autocorrection. To enable it, add the following to your settings.json:

{
  "languages": {
    "Ruby": {
      "language_servers": ["rubocop", "ruby-lsp", "!solargraph", "..."]
    }
  }
}

Setting up solargraph

Zed currently doesn't install Solargraph automatically. To use Solargraph, you need to install the gem. Zed just looks for an executable called solargraph on your PATH.

You can install the gem manually with the following command:

gem install solargraph

Alternatively, if your project uses Bundler, you can add the Solargraph gem to your Gemfile:

gem 'solargraph', group: :development

Solargraph has formatting and diagnostics disabled by default. We can tell Zed to enable them by adding the following to your settings.json:

{
  "lsp": {
    "solargraph": {
      "initialization_options": {
        "diagnostics": true,
        "formatting": true
      }
    }
  }
}

Configuration

Solargraph reads its configuration from a file called .solargraph.yml in the root of your project. For more information about this file, see the Solargraph configuration documentation.

Setting up ruby-lsp

Zed currently doesn't install Ruby LSP automatically. To use Ruby LSP, you need to install the gem. Zed just looks for an executable called ruby-lsp on your PATH.

You can install the gem manually with the following command:

gem install ruby-lsp

Ruby LSP uses pull-based diagnostics which Zed doesn't support yet. We can tell Zed to disable it by adding the following to your settings.json:

{
  "lsp": {
    "ruby-lsp": {
      "initialization_options": {
        "enabledFeatures": {
          "diagnostics": false
        }
      }
    }
  }
}

Setting up rubocop LSP

Zed currently doesn't install rubocop automatically. To use rubocop, you need to install the gem. Zed just looks for an executable called rubocop on your PATH.

You can install the gem manually with the following command:

gem install rubocop

Rubocop has unsafe autocorrection disabled by default. We can tell Zed to enable it by adding the following to your settings.json:

{
  "lsp": {
    "rubocop": {
      "initialization_options": {
        "safeAutocorrect": false
      }
    }
  }
}

Using the Tailwind CSS Language Server with Ruby

It's possible to use the Tailwind CSS Language Server in Ruby and ERB files.

In order to do that, you need to configure the language server so that it knows about where to look for CSS classes in Ruby/ERB files by adding the following to your settings.json:

{
  "languages": {
    "Ruby": {
      "language_servers": ["tailwindcss-language-server", "..."]
    }
  },
  "lsp": {
    "tailwindcss-language-server": {
      "settings": {
        "includeLanguages": {
          "erb": "html",
          "ruby": "html"
        },
        "experimental": {
          "classRegex": ["\\bclass:\\s*['\"]([^'\"]*)['\"]"]
        }
      }
    }
  }
}

With these settings you will get completions for Tailwind CSS classes in HTML attributes inside ERB files and inside Ruby/ERB strings that are coming after a class: key. Examples:

# Ruby file:
def method
  div(class: "pl-2 <completion here>") do
    p(class: "mt-2 <completion here>") { "Hello World" }
  end
end

# ERB file:
<%= link_to "Hello", "/hello", class: "pl-2 <completion here>" %>
<a href="/hello" class="pl-2 <completion here>">Hello</a>