如何在 Visual Studio 代码上调试 Ruby 代码?
How to debug Ruby code on Visual Studio Code?
我是 VSCode 的新手,但是,我在网站上阅读时确实下载了所需的扩展。到目前为止,我无法在VSCode上调试Ruby,我不确定问题出在哪里。它就是不启动...我认为它不会将代码视为 Ruby。
每当我尝试 运行 代码时,我都会在调试 window 中看到 "downloading C# extensions..."。这当然很奇怪。
有帮助吗?
只要您按照正确的步骤操作,这实际上相当容易。
首先,您必须下载 Ruby Extension,它可以在 vs 代码市场上获得,或者只需通过 VS 代码本身的扩展选项卡即可:只需搜索 Ruby,安装它,然后重新加载 VS 代码 [更新:vscode 无需重新加载即可完美加载新扩展]。
其次,您必须遵循此扩展的调试指南,该指南可在我提供的 GitHub link 或 vs 代码市场中找到。这是您最感兴趣的部分,但您也可以看到 original wiki:
Install Ruby Dependencies
In this extension, we implement ruby debug ide protocol to allow VS
Code to communicate with ruby debug, it requires ruby-debug-ide to be
installed on your machine. This is also how RubyMine/NetBeans does by
default.
If you are using JRuby or Ruby v1.8.x (jruby, ruby_18, mingw_18), run
gem install ruby-debug-ide
The latest version is 0.6.0. Make sure ruby-debug-base
is installed together with ruby-debug-ide
.
If you are using Ruby v1.9.x (ruby_19, mingw_19), run
gem install ruby-debug-ide
The latest version is 0.6.0. Make sure ruby-debug-base19x
is installed together with ruby-debug-ide
.
If you are using Ruby v2.x
gem install ruby-debug-ide -v 0.6.0 (or higher versions)
gem install debase -v 0.2.1 (or higher versions)
Add VS Code config to your project
Go to the debugger view of VS Code and hit the gear icon. Choose Ruby
or Ruby Debugger from the prompt window, then you'll get the sample
launch config in .vscode/launch.json. The sample launch configurations
include debuggers for RSpec (complete, and active spec file) and
Cucumber runs. These examples expect that bundle install --binstubs
has been called. Detailed instruction for debugging Ruby
Scripts/Rails/etc
Read following instructions about how to debug ruby/rails/etc locally
or remotely
如果您按照这些步骤操作,您将在步骤 1 中安装所有依赖项。
第 2 步帮助您配置项目工作区以开始调试用 ruby 编写的代码。
完成第 2 步后,您应该可以开始调试了。
这是一个简单的配置,我在最近的 ruby 项目中使用它来简单地调试当前打开的文件。这在我 linked
的第二步中得到了充分解释
{
"name": "Debug Local File",
"type": "Ruby",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "${file}"
}
"program": "${file}" 是启用调试当前打开文件的行。
为 Visual Studio 代码安装 Ruby Debug 扩展
我是 VSCode 的新手,但是,我在网站上阅读时确实下载了所需的扩展。到目前为止,我无法在VSCode上调试Ruby,我不确定问题出在哪里。它就是不启动...我认为它不会将代码视为 Ruby。 每当我尝试 运行 代码时,我都会在调试 window 中看到 "downloading C# extensions..."。这当然很奇怪。 有帮助吗?
只要您按照正确的步骤操作,这实际上相当容易。 首先,您必须下载 Ruby Extension,它可以在 vs 代码市场上获得,或者只需通过 VS 代码本身的扩展选项卡即可:只需搜索 Ruby,安装它,然后重新加载 VS 代码 [更新:vscode 无需重新加载即可完美加载新扩展]。 其次,您必须遵循此扩展的调试指南,该指南可在我提供的 GitHub link 或 vs 代码市场中找到。这是您最感兴趣的部分,但您也可以看到 original wiki:
Install Ruby Dependencies
In this extension, we implement ruby debug ide protocol to allow VS Code to communicate with ruby debug, it requires ruby-debug-ide to be installed on your machine. This is also how RubyMine/NetBeans does by default.
If you are using JRuby or Ruby v1.8.x (jruby, ruby_18, mingw_18), run
gem install ruby-debug-ide
The latest version is 0.6.0. Make sure
ruby-debug-base
is installed together withruby-debug-ide
.
If you are using Ruby v1.9.x (ruby_19, mingw_19), run
gem install ruby-debug-ide
The latest version is 0.6.0. Make sure
ruby-debug-base19x
is installed together withruby-debug-ide
.
If you are using Ruby v2.x
gem install ruby-debug-ide -v 0.6.0 (or higher versions) gem install debase -v 0.2.1 (or higher versions)
Add VS Code config to your project
Go to the debugger view of VS Code and hit the gear icon. Choose Ruby or Ruby Debugger from the prompt window, then you'll get the sample launch config in .vscode/launch.json. The sample launch configurations include debuggers for RSpec (complete, and active spec file) and Cucumber runs. These examples expect that bundle install --binstubs has been called. Detailed instruction for debugging Ruby Scripts/Rails/etc
Read following instructions about how to debug ruby/rails/etc locally or remotely
如果您按照这些步骤操作,您将在步骤 1 中安装所有依赖项。 第 2 步帮助您配置项目工作区以开始调试用 ruby 编写的代码。 完成第 2 步后,您应该可以开始调试了。 这是一个简单的配置,我在最近的 ruby 项目中使用它来简单地调试当前打开的文件。这在我 linked
的第二步中得到了充分解释{
"name": "Debug Local File",
"type": "Ruby",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "${file}"
}
"program": "${file}" 是启用调试当前打开文件的行。
为 Visual Studio 代码安装 Ruby Debug 扩展