Reputation: 17527
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?
Upvotes: 4
Views: 1215
Reputation: 2332
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:
Big kudos to the author
Upvotes: 1