The Best VS Code Extensions for Anyone Working in Ruby

The Best VS Code Extensions for Anyone Working in Ruby

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.

No alt text provided for this image

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

No alt text provided for this image
“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.

3. Ruby Solargraph by Castwide

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

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!

要查看或添加评论,请登录

社区洞察

其他会员也浏览了