无法在VS Code中调试rake任务

问题描述 投票:3回答:1

我已正确配置我的环境,以使用VS Code调试Rails应用。

对于调试Rails Server正常工作。当我开始调试时,它会引导服务器并在我标记的断点处停止。

但是,我不知道如何调试本地文件,例如rake任务。它甚至运行任务,但不会在断点处停止。

下面是我设置环境的方式。

Ubuntu running on WSL2.
VSCode running on windows

安装扩展名:

Remote - WSL from Microsoft
Ruby from PengLv

已安装的宝石:

gem install ruby-debug-ide
gem install debase

Gemfile:

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

/。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任务本身位于/lib/taks/fd.rake:

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

为了进行比较,可以正常工作的调试Rails服务器的配置是:

{
  // 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"
      ]
    }
  ]
}

就像我在上面说的那样,它运行任务,但不会在断点处停止。有人可以帮助我吗?

ruby-on-rails debugging visual-studio-code rake-task
1个回答
0
投票

Ruby on Rails debugging in VS Code建议您需要添加pathToBundlerpathToRDebugIDE

此外,VS Code对于RVM环境变量也不明智,因此我总是为每个配置配置env。

  • 注意:gem env将为您提供GEM PATHS,用于设置GEM_HOMEGEM_PATH变量
  • 注意:echo $PATH-仅使用整个路径

而且,尽管我没有使用Docker,但我将showDebuggerOutput设置为true。

这样做会使您的配置看起来像:

{
  "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"
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.