gpt4 book ai didi

ruby-on-rails - 无法在 VS Code 中调试 rake 任务

转载 作者:行者123 更新时间:2023-12-02 04:22:16 25 4
gpt4 key购买 nike

我正确配置了我的环境以在 VS Code 中调试 rails 应用程序。

它适用于调试 Rails 服务器。当我开始调试时,它会启动服务器并在我标记的断点处停止。

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

下面是我如何设置我的环境。

Ubuntu running on WSL2.
VSCode running on windows

安装了扩展:
Remote - WSL from Microsoft
Ruby from PengLv

安装的 gem :
gem install ruby-debug-ide
gem install debase

gem 文件:
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 in VS Code建议您需要添加 pathToBundlerpathToRDebugIDE .

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

  • 注:gem env会给你你的GEM PATHS , 用于设置 GEM_HOMEGEM_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"
    }
    }

    关于ruby-on-rails - 无法在 VS Code 中调试 rake 任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58940969/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com