Modern Developer

How to work with Ruby and VS Code

How to work with Ruby and VS Code

"How do I use VS Code with Ruby after installing the Ruby 3.2.3.", someone asked.

Here was my quick response, which I have archived here for future me:

I had the same issue but I found a great setup. YMMV but for my purpose I’m using ruby for learning and will use DRTK to make some games so I need a Windows machine. I would def use WSL2 for Rails work. This setup got me going with syntax highlighting, debugging, LSP, and IntelliSense.

So, first thing, it sounds like you have Ruby installed via the Ruby installer.

Install the following extensions in vscode:

* VS Code rdbg Ruby Debugger * Ruby Solargraph and the Solargraph gem * StandardRuby – and auto fix linting issues * ruby-rubocop * Code Runner – great for running single files.

AVOID installing these extensions on Windows:

This is just a recommendation nothing against these plugins per se.

Make sure the standardrb extension can find the standardrb.bat file for running the LSP.

I recommend using VS code workspaces https://code.visualstudio.com/docs/editor/workspaces with Ruby projects in vscode.

Here are my VS Code User settings. Hope it helps!

[ruby]: {
      “editor.defaultFormatter”: “testdouble.vscode-standard-ruby”, // Use the Ruby LSP as the default formatter
      “editor.formatOnSave”: false, // Format files automatically when saving
      “editor.tabSize”: 2, // Use 2 spaces for indentation
      “editor.insertSpaces”: true, // Use spaces and not tabs for indentantion
      “editor.semanticHighlighting.enabled”: true, // Enable semantic highlighting
      “editor.formatOnType”: true,
      “files.trimTrailingWhitespace”: true,
      “files.insertFinalNewline”: true,
      “files.trimFinalNewlines”: true,
      “editor.rulers”: [
        120
      ], // Enable formatting while typing
    },[jsonc]: {
      “editor.defaultFormatter”: “vscode.json-language-features”
    },
    “standardRuby.mode”: “enableUnconditionally”,
    “standardRuby.commandPath”: “C:\Ruby32-x64\bin\standardrb.bat”,
    “ruby.rubocop.suppressRubocopWarnings”: true,
    “ruby.rubocop.onSave”: false,