我已正确配置我的环境,以使用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
宝石文件:
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"
]
}
]
}
就像我上面说的那样,它运行任务,但不会在断点处停止。 有人可以帮我吗?
答案 0 :(得分:2)
Ruby on Rails debugging in VS Code建议您需要添加pathToBundler
和pathToRDebugIDE
。
此外,VS Code对RVM环境变量也不明智,因此我总是为每种配置配置env。
gem env
将为您提供GEM PATHS
,用于设置GEM_HOME
和GEM_PATH
变量echo $PATH
-仅使用整个路径这样做会使您的配置看起来像这样:
{
"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"
}
}