ruby - 如何在 Visual Studio Code 上调试 Ruby 代码?

标签 ruby visual-studio visual-studio-code vscode-settings

我是 VSCode 的新手,但是,我在网站上阅读时确实下载了所需的扩展。到目前为止,我无法在 VSCode 上调试 Ruby,我不确定问题出在哪里。它只是不启动...我认为它不会将代码视为 Ruby。 每当我尝试运行代码时,我都会在调试窗口中看到“正在下载 C# 扩展...”。这当然很奇怪。 有帮助吗?

最佳答案

只要您按照正确的步骤操作,这实际上相当容易。 首先,你必须下载 Ruby Extension它可以在 vs code 市场上获得,也可以通过 VS code 本身的扩展选项卡获得:只需搜索 Ruby,安装它,然后重新加载 VS Code [更新:vscode 可以完美地加载新扩展而无需重新加载]。 其次,您必须遵循此扩展的调试指南,该指南可在我提供的 GitHub 链接或 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

01 Debugger installation

02 Launching from VS Code

03 Attaching to a debugger

04 Running gem scripts

05 Example configurations

如果您按照这些步骤操作,您将在步骤 1 中安装所有依赖项。 第 2 步帮助您配置项目工作区以开始调试用 ruby​​ 编写的代码。 完成第 2 步后,您应该可以开始调试了。 这是一个简单的配置,我在最近的 ruby​​ 项目中使用它来简单地调试当前打开的文件。这在我链接的第二步中得到了充分解释

{
   "name": "Debug Local File",
   "type": "Ruby",
   "request": "launch",
   "cwd": "${workspaceRoot}",
   "program": "${file}"
}

"program": "${file}"是启用调试当前打开文件的行。

关于ruby - 如何在 Visual Studio Code 上调试 Ruby 代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51539711/

相关文章:

git - 对于使用 WSL2 签名的 git 提交,Windows 10 上的 Visual Studio Code 中没有 GPG 密码提示

ruby - 检查字符串变量是否在一组字符串中

visual-studio-code - Visual Studio Code中的HTML5 canvas智能感知

ruby - 连续添加数字

c# - 对于 .net core 3.0 中的 wpf 项目,Xaml UI Designer 处于非事件状态

c++ - 在 Visual Studio 中循环

javascript - 如果检测到错误,则禁用从 typescript 生成 JavaScript

visual-studio-code - 如何从 Visual Studio Code 扩展中搜索符号

ruby - 响应重定向编码的 RestClient 错误

Ruby-on-rails Postgres 查询