Skip to content

Instantly share code, notes, and snippets.

@floptwo
Last active November 29, 2024 15:10
Show Gist options
  • Save floptwo/fdb2df57e7e7cde3781e64de0007f5a9 to your computer and use it in GitHub Desktop.
Save floptwo/fdb2df57e7e7cde3781e64de0007f5a9 to your computer and use it in GitHub Desktop.
LSP for OLD ruby (VSCode & Zed)

Sources: https://stackoverflow.com/a/78071275 & https://nrogap.medium.com/install-ruby-lsp-in-vs-code-128f02571ea0

Make Ruby LSP work even old ruby projects or just outside of your current project

Outside your main project, create a folder :

Make sure to install a ruby version >= 3.0.0 with YJIT (I'm using rbenv):

$ RUBY_CONFIGURE_OPTS="--enable-yjit" rbenv install 3.2.2

Add the .ruby-version file :

3.2.2

Add the Gemfile file :

# frozen_string_literal: true

source 'https://rubygems.org'

ruby '3.2.2'

gem 'ruby-lsp'
# ...Any other lsp gems you want

Install the gems with bundler

$ bundle install

If you're using rbenv don't forget to run rbenv rehash

Zed

Source: https://zed.dev/docs/languages/ruby#configuring-a-language-server

In the directory you have to create a binstub

$ bundle binstubs ruby-lsp

In your Ruby project, create a Zed settings file .zed/settings.json

{
  "languages": {
      "Ruby": {
          "language_servers": ["ruby-lsp", "!solargraph", "!rubocop", "..."]
      }
  },
  "lsp": {
      "ruby-lsp": {
          "binary": {
              "path": "../../path/to/the/directory/bin/ruby-lsp"
          }
      }
  }
 }

Install Ruby extension and you're good to go.

VSCode

Source: https://github.com/Shopify/ruby-lsp/blob/main/vscode/README.md#using-a-custom-gemfile

In your Ruby project, create a VSCode settings file .vscode/settings.json

{
  "rubyLsp.bundleGemfile": "../../path/to/the/directory/Gemfile",
}

Install Ruby LSP plugin and restart VSCode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment