如何从Visual Studio Code运行和调试Ruby on Rails? [英] How do you run and debug Ruby on Rails from Visual Studio Code?
问题描述
-
如何使用内置的Visual Studio代码启动/调试功能启动Ruby on Rails?
How can you launch Ruby on Rails using the built-in Visual Studio Code Launch/Debug features?
如何解决Debugger terminal error: Process failed: spawn rdebug-ide ENOENT
错误?
推荐答案
设置和启动
- 安装 VS Code Ruby插件 (点击⌘ + ⇧ + P 并在提示符下键入
ext install
,然后搜索ruby
) - 安装一些必需的Ruby gems
- Install the VS Code Ruby plugin (hit ⌘+⇧+P and type
ext install
in the prompt, then search forruby
) - Install some required Ruby gems
gem install ruby-debug-ide
gem install debase
- 在Visual Studio代码中添加启动配置. (如下所示的示例配置)
- Add a launch configuration in Visual Studio Code (example configuration shown below)
{
"name": "Rails server",
"type": "Ruby",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "${workspaceRoot}/bin/rails",
"env": {
"PATH": "YOUR_PATH_HERE",
"GEM_HOME": "YOUR_GEM_HOME_HERE",
"GEM_PATH": "YOUR_GEM_PATH_HERE",
"RUBY_VERSION": "YOUR_RUBY_VERSION_HERE"
},
"args": [
"server"
]
}
在某些情况下,您可能不需要指定
env
部分. 在其他情况下,您可以使用CLI启动VS Code(在终端上),它在某些系统上会自动设置正确的环境变量.
In some cases you might not need to specify the
env
section. In other cases you can launch VS Code using the CLI (i.e. from the terminal), which on some systems automatically sets the correct environment variables.
- 运行!
问题排查
如果出现以下错误
Troubleshooting
If you get the following error
Debugger terminal error: Process failed: spawn rdebug-ide ENOENT
您的环境变量(env
)很可能未设置,并且插件找不到所需的二进制文件.
Your environment variables (env
) are most likely not set and the plugin cannot find the necessary binaries.
- 确保已安装所有gem,如果使用捆绑程序,请尝试运行
bundler install --binstubs
. - 确保在启动配置中设置了
env
部分.运行以下shell命令以生成您的env
:
- Make sure all gems are installed and try running
bundler install --binstubs
if you use bundler. - Make sure the
env
section is set in your launch configuration. Run the following shell command to generate yourenv
:
printf "\n\"env\": {\n \"PATH\": \"$PATH\",\n \"GEM_HOME\": \"$GEM_HOME\",\n \"GEM_PATH\": \"$GEM_PATH\",\n \"RUBY_VERSION\": \"$RUBY_VERSION\"\n}\n\n"
Windows
请确保使用path
变量的正确拼写(和大小写),即Windows上的Path
Windows
Make sure to use the correct spelling (and capitalization) of the path
variable, i.e. Path
on Windows
- https://github.com/rubyide/vscode-ruby/issues/214#issuecomment-393111908
- https://www.reddit.com/r/vscode/comments/5w1acs/getting_error_debugger_terminal_error_process/
- 如何在Visual Studio Code中的launch.json中扩展$ PATH?
这篇关于如何从Visual Studio Code运行和调试Ruby on Rails?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!