gpt4 book ai didi

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

转载 作者:数据小太阳 更新时间:2023-10-29 06:46:16 25 4
gpt4 key购买 nike

我是 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 VSCode to communicate with ruby debug, it requires ruby-debug-ide to beinstalled on your machine. This is also how RubyMine/NetBeans does bydefault.

  • 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 Rubyor Ruby Debugger from the prompt window, then you'll get the samplelaunch config in .vscode/launch.json. The sample launch configurationsinclude debuggers for RSpec (complete, and active spec file) andCucumber runs. These examples expect that bundle install --binstubshas been called. Detailed instruction for debugging RubyScripts/Rails/etc

Read following instructions about how to debug ruby/rails/etc locallyor 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/

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