How to use Ruby on Windows with VS Code

Someone asked on r/Ruby ,how to use VSCode with Ruby after installing the latest Ruby 3.2.3?

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.

Now, in VS code, AVOID installing these extensions on Windows with Ruby installer, they cause pain and confusion:

  • Ruby for VS Code ( deprecated/ out of date )
  • Ruby shopify (ruby-lsp doesn’t work for me as)
  • VSCode Ruby ( out of date)
    This is just a recommendation nothing against these plugins per se.

Do install:

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

The key thing was making sure the standardrb extension can find the.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,
 
 


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

en_USEnglish