I'm trying to set a breakpoint in a Rails application from VSCode on a Mac. I'm using ASDF to install Ruby etc.
The default launch configuration in VSCode for Rails looks like this:
{
"name": "Rails server",
"type": "Ruby",
"request": "launch",
"program": "${workspaceRoot}/bin/rails",
"args": [
"server"
]
}
That fails because my which rails is Users/timregan/.asdf/shims/rails. But if I replace "program": "${workspaceRoot}/bin/rails" in the launch.json with "program": "/Users/timregan/.asdf/shims/rails" I get this error message when I try to launch a debugging session:
Uncaught exception: /Users/timregan/.asdf/shims/rails:3: unknown regexp options - hbrw
exec /opt/homebrew/opt/asdf/libexec/bin/asdf ex...
^~~~~~~~~
/Users/timregan/.asdf/shims/rails:3: syntax error, unexpected local variable or method, expecting `do' or '{' or '('
.../opt/asdf/libexec/bin/asdf exec "rails" "$@"
... ^~~~
/Users/timregan/.asdf/installs/ruby/3.0.3/bin/rdebug-ide:25:in `load'
/Users/timregan/.asdf/installs/ruby/3.0.3/bin/rdebug-ide:25:in `'
What is the correct setting to use in VSCode's launch.json to debug Rails when using ASDF?
This is due to ruby interpreting the . in .asdf or user.name as a regular expression and messing up the paths.
What solved it, was adding binstubs to wrap the real path of the executable (.../.asdf/.../rspec) with a {workspaceFolder}/bin/rspec
bundle binstubs bundler ruby-debug-ide solargraph rspec-core
and the binstubs to reference the shimed executables:
"program": "${workspaceFolder}/bin/rspec",
"pathToRDebugIDE": "/${workspaceFolder}/bin/rdebug-ide",
"pathToBundler": "${workspaceFolder}/bin/bundle",
Source: Found the solution in this article where you get a step-by-step on setting up your project + launch.json:
https://dev.to/abstractart/easy-way-to-setup-debugger-and-autocomplete-for-ruby-in-visual-studio-code-2gcc
Big kudos to the author
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With