Can't debug rake task in VS Code
Asked Answered
H

1

6

I configured my environment properly to debug rails apps in VS Code.

It works fine for debug Rails Server. When I start the debug, it boots the server and stop at the breakpoints that I have marked.

But, I can't figure out how to debug local files, like rake tasks. It even runs the task, but it does not stop at the breakpoints.

Below is how I set up my environment.

Ubuntu running on WSL2.
VSCode running on windows

Installed the extension:

Remote - WSL from Microsoft
Ruby from PengLv

Installed gems:

gem install ruby-debug-ide
gem install debase

Gemfile:

gem 'ruby-debug-ide'
gem 'debase'`

Configuration for debug local file at /.vscode/launch.json:

{
  // Use IntelliSense to learn about possible attributes.
  // Hover to view descriptions of existing attributes.
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Rake fd:test",
      "type": "Ruby",
      "request": "launch",
      "cwd": "${workspaceRoot}",
      "program": "${workspaceRoot}/bin/rake",
      "useBundler": true,
      "args": ["fd:test"]
    }
  ]
}

Rake task itself at /lib/taks/fd.rake:

namespace :fd do
  task test: :environment do
    a = 10
    p "teste"
    b = 20
    c = 30
  end
end

The configuration for debug Rails server that works properly, just for comparation, is:

{
  // Use IntelliSense to learn about possible attributes.
  // Hover to view descriptions of existing attributes.
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [

    {
      "name": "Rails server",
      "type": "Ruby",
      "request": "launch",
      "program": "${workspaceRoot}/bin/rails",
      "args": [
        "server"
      ]
    }
  ]
}

Like I said above, it runs the task, but does not stop on breakpoints. Anyone can help me out?

Haematogenesis answered 19/11, 2019 at 18:50 Comment(1)
are you able to debug the rake task now?Algetic
H
2

The Ruby on Rails debugging in VS Code suggests you need to add pathToBundler and pathToRDebugIDE.

Also, VS Code is not wise to RVM environment variables so I always configure env for each configuration.

  • note: gem env will give you your GEM PATHS, used to set GEM_HOME and GEM_PATH variables
  • note: echo $PATH - just use the whole path

Doing so would make your configuration look something like:

{
  "name": "Rake fd:test",
  "type": "Ruby",
  "request": "launch",
  "cwd": "${workspaceRoot}",
  "program": "${workspaceRoot}/bin/rake",
  "useBundler": true,
  "pathToBundler": "/Users/johng/.rvm/rubies/ruby-2.5.3/bin/bundle",
  "pathToRDebugIDE": "/Users/johng/.rvm/gems/ruby-2.5.3@gemset253/gems/ruby-debug-ide-0.7.0/bin/rdebug-ide",
  "args": ["fd:test"],
  "showDebuggerOutput": true,
  "env": {
      "PATH": "/Users/johng/.rvm/gems/ruby-2.5.3@gemset253/bin:/Users/johng/.rvm/gems/ruby-2.5.3@global/binƒ/Users/johng/.rvm/rubies/ruby-2.5.3/bin:/Users/johng/.rvm/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/sbin",
      "GEM_HOME": "/Users/johng/.rvm/gems/ruby-2.5.3@gemset253",
      "GEM_PATH": "/Users/johng/.rvm/gems/ruby-2.5.3@gemset253:/Users/johng/.rvm/rubies/ruby-2.5.3/lib/ruby/gems/2.5.0"
  }
}
Hubblebubble answered 31/1, 2020 at 22:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.