The Best VS Code Extensions for Anyone Working in Ruby

Better tooling, better programming

Peter Ayeni
Oct 17, 2019 · 4 min read
Image for post
Image for post

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.

Features

  • 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

Installation

Search for 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.

Image for post
Image for post
Source

Before we configure RuboCop, it’s good to get the background understanding of what powers it behind the scenes.

Image for post
Image for post

“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

Installation of Ruby and RuboCop is required.

gem install rubocop
  • Type F1 (or Command + Shift + P)
  • Execute “Extensions: install extension”
  • Type 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.

  1. Add the Rubocop gem to my gemfile gem 'rubocop'
  2. bundle
  3. run rubocop --auto-gen-config. This autogenerates a configuration file for my current project.
  4. To allow RuboCop to automatically format my code and apply best practices, I then run rubocop -a.

Configuration

Specify configuration (via navigating to File > Preferences > Workspace Settings) and editing the file settings.json):.

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)
"ruby.rubocop.executePath": "",

// 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.
"ruby.rubocop.configFilePath": "/path/to/config/.rubocop.yml",

// default true
"ruby.rubocop.onSave": true
}

3. Ruby Solargraph by Castwide

Solargraph is a language server that provides Intellisense, code completion, and in-line documentation for Ruby.

Image for post
Image for post

Features

  • 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

Requirements

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.

Bonus

These are other VS Code extensions I think will make your life easier as a new Ruby developer.

  1. Ruby Language Colorization by Drew Cain
  2. Simple Ruby ERB by Victor Ortiz Heredia
  3. 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.

Happy hacking!

Better Programming

Advice for programmers.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store