The Best VS Code Extensions for Anyone Working in Ruby
Better tooling, better programming
One of the things that makes VS Code super brilliant is the ability to install extensions that further give it more capability. So let’s dive into it. I assume you already have VS Code. If not, install it — it runs on any operating system you’re using, so you’ll be fine.
For the purpose of this tutorial, we’ll be using four VS Code extensions, and they all work seamlessly together to supercharge you IDE and Ruby coding experience.
Ruby by Peng Lv
This extension provides Ruby language and debugging support for VS Code.
- Automatic Ruby-environment detection with support for RVM, rbenv, chruby, and asdf
- Lint support via RuboCop, Standard, and Reek
- Format support via RuboCop, Standard, Rufo, and RubyFMT
- Semantic code-folding support
- Semantic highlighting support
- Basic Intellisense support
ruby in the VS Code Extension Gallery, and install it.
This Ruby extension depends on our next extension (you’ll have noticed that from the feature list).
2. Ruby RuboCop by misogi
This extension provides interfaces to RuboCop for VS Code. RuboCop is a code analyzer for ruby.
Before we configure RuboCop, it’s good to get the background understanding of what powers it behind the scenes.
“RuboCop is a Ruby static code analyzer and code formatter. Out of the box it will enforce many of the guidelines outlined in the community Ruby Style Guide.”
— RuboCop documentation
The Ruby Style Guide is a document every new Rubyist should check out. It’s like the Ten Commandments and will help you speak like the locals while learning the new language. It enables you to write Ruby code like the pros.
What RuboCop helps you with is taking in all of the rules from the style guide and making your code conform to them, allowing you to focus on the most important thing: solving problems.
Installation of Ruby and RuboCop is required.
gem install rubocop
- Type F1 (or Command + Shift + P)
- Execute “Extensions: install extension”
rubocop, and execute
ext install ruby-rubocop
RuboCop comes with a configuration file you can configurem as explained below. I just use these simple steps — you can go with any option you desire.
- Add the Rubocop gem to my gemfile
rubocop --auto-gen-config. This autogenerates a configuration file for my current project.
- To allow RuboCop to automatically format my code and apply best practices, I then run
Specify configuration (via navigating to File > Preferences > Workspace Settings) and editing the file
You can also use the configuration file that comes with RuboCop to automate your configuration. It’s well documented and easy to configure.
// If not specified searches for 'rubocop' executable available on PATH (default and recommended)
// You can use specific path
// "ruby.rubocop.executePath": "/Users/you/.rbenv/shims/"
// "ruby.rubocop.executePath": "/Users/you/.rvm/gems/ruby-2.3.2/bin/"
// "ruby.rubocop.executePath": "D:/bin/Ruby22-x64/bin/"
// If not specified, it assumes a null value by default.
// default true
3. Ruby Solargraph by Castwide
Solargraph is a language server that provides Intellisense, code completion, and in-line documentation for Ruby.
- Context-aware suggestions and documentation for the Ruby core
- Detection of some variable types and method return values (e.g.,
String.new.returns string-instance methods)
- Identification of local, class, and instance variables within the current scope
- Find references and rename symbols (experimental as of Solargraph gem v0.22.0)
- Support for gems
- Near-complete support for the Ruby core and stdlib
- Partial support for Ruby on Rails
You need to install the Ruby gem:
gem install solargraph
After installing the gem, head to your VS Code extension panel, and search for Ruby Solargraph. Then install it, and you’re good to roll.
These are other VS Code extensions I think will make your life easier as a new Ruby developer.
- Ruby Language Colorization by Drew Cain
- Simple Ruby ERB by Victor Ortiz Heredia
- Ruby on Rails by Hridoy
Although this tutorial focuses on VS Code, other IDEs also have their own extensions, so no matter what IDE you’re using, check out their respective extensions.
This is just to set the stage for what’s coming. In the upcoming piece, I’ll be sharing a tutorial series on getting started with Ruby for an absolute beginner. I’m sure it will be useful for you or someone in your network that wants to start coding.