Install Ruby LSP in VS Code for Old Ruby
2 min readOct 26, 2023
Regarding my Ruby by Peng Lv is deprecated. VS Code suggested me to install Ruby LSP. But it’s required ruby version 3 and above!
Good luck that we can force Ruby LSP to work on ruby 3.x.x project instead of the real project.
Step by Step
Step 1: Create a new ruby project version 3+
1/ Install and specify your ruby version
$ rvm install 3.1.4
$ rvm use 3.1.4
2/ Initial the new project
$ mkdir ruby-extensions
$ cd ruby-extensions
$ touch Gemfile
$ touch .ruby-version
3/ Edit Gemfile, and .ruby-version. They should looks like these
# Gemfile
source 'https://rubygems.org'
ruby '3.1.4'
# Ruby LSP
gem 'rubocop'
gem 'ruby-lsp'
# .ruby-version
3.1.4
Step 2: Bundle Install the project
$ bundle install
After this, we should get Gemfile.lock
Step 3: Install extensions to VS Code
Step 4: Setting Ruby LSP
In VS Code Settings, add/edit these with your own settings
rubyLsp.rubyVersionManager
rubyLsp.bundleGemfile
...
"[ruby]": {
"editor.defaultFormatter": "Shopify.ruby-lsp",
...
}
...
"rubyLsp.rubyVersionManager": "rvm",
"rubyLsp.bundleGemfile": "/Users/pagorn/ruby-extensions/Gemfile",
...
Step 5: Restart Vistual Studio Code
- Quite all VS Code.
- Open VS Code with the new project again.
- Click
{}
on the right bottom, we should see a popup without any error messages
Step 6: Let’s check the old ruby project
Same as Step 5, but this time we’ll open the old project which ruby version is 2.7.2 Check if Ruby LSP works and can Go to definition