I would like to debug in Visual Studio Code my ruby on rails project, with attach debugging, but my Visual Studio Code debugger doesn't stop at breakpoints.
My ruby version:2.4.4
My rails version:5.0.1
My Visual Studio Code version :1.35.1
I did install
ruby extension for Visual Studio Code
gem install debase
gem install ruby-debug-ide
and my configuration in launch.json is
{
"name": "Debug Attach",
"type": "Ruby",
"request": "attach",
"cwd": "${workspaceRoot}",
"remoteWorkspaceRoot": "bin/rails",
"remoteHost": "127.0.0.1",
"remotePort": "3000",
"showDebuggerOutput": true
}
in debug console i get
"Debugger error: Client: Error: write EPIPE"
Thank you :)
Please try to add paths of bundle and ruby-debug-ide in your launch.json :
{
"name": "Debug Attach",
"type": "Ruby",
"request": "attach",
"cwd": "${workspaceRoot}",
"useBundler": true,
"pathToBundler": "/path/to/rubygem/wrappers/bundle",
"pathToRDebugIDE": "/path/to/rubygem/gems/ruby-debug-ide-x.x.x/bin/rdebug-ide",
"remoteWorkspaceRoot": "bin/rails",
"remoteHost": "127.0.0.1",
"remotePort": "3000",
"showDebuggerOutput": true
}
I hope that helpful
Related
I am using ruby-debug-ide and debase for debugging in vs code in that when i start debugging by default server is started in development environment, how to debug in a different environment like test/qa? how to configure this launch.json
My launch.json file
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Rails server",
"type": "Ruby",
"request": "launch",
"program": "${workspaceRoot}/bin/rails",
"args": [
"server"
],
"showDebuggerOutput": true,
"env": {
"PATH": "/Users/giri.shankar/.rvm/gems/ruby-2.6.3#codeforkout/bin:/Users/giri.shankar/.rvm/gems/ruby-2.6.3#global/bin:/Users/giri.shankar/.rvm/rubies/ruby-2.6.3/bin:/Users/giri.shankar/.rvm/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin",
"GEM_HOME": "/Users/giri.shankar/.rvm/gems/ruby-2.6.3#codeforkout",
"GEM_PATH": "/Users/giri.shankar/.rvm/gems/ruby-2.6.3#codeforkout:/Users/giri.shankar/.rvm/gems/ruby-2.6.3#global",
"RUBY_VERSION": "ruby-2.6.3"
}
}
]
}
For time being i changed the default environment to qa by adding the below line in boot.rb, so now whenever i run rails s qa environment is booted by default
ENV["RACK_ENV"] = "qa"
You just have to add -e test to the rails server command:
{
...
"args": [
"server -e test"
]
}
Despite having spent about the last three hours trying to get this working I cannot for the life of my get RSpec to work with the debugger on VSCode. I can get Rspec to run in the terminal on VSCode but that doesn't give me any of the IDE's debugging functionality for inspecting and stepping.
This is what I've got in my launch.json file:
{
"version": "0.2.0",
"configurations": [
{
"name": "Run RSpec - all",
"type": "Ruby",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "/Users/my-home-dir/.rvm/gems/ruby-2.6.5#project-gemset-name/wrappers/rspec",
"pathToRDebugIDE": "/Users/my-home-dir/.rvm/gems/ruby-2.6.5#project-gemset-name/gems/ruby-debug-ide-0.7.2",
"args": [
"--pattern",
"${workspaceRoot}/spec/**/*_rspec.rb"
]
}
]
}
And my gemfile contains:
gem 'ruby-debug-ide', '~>0.7.2'
gem 'debase', '~>0.2.4.1'
I've got a feeling that the errors may be coming about due to in incompatibility between RVM and VSCode but I've no idea how to unwind that issue.
This was all setup as per the Microsoft recipe here: https://github.com/Microsoft/vscode-recipes/tree/master/debugging-Ruby-on-Rails
Every time I run this setup I get the following error in the debug console:
Debugger terminal error: Process failed: spawn rdebug-ide ENOENT
Is there any way to get this to run? Also is there any way to get it to use guard so that it runs automatically?
I got it working. Unfortunately, I don't use RVM. So, my solution involves rbenv. I'm sharing it here anyway in case it helps you, or someone else.
which rspec pointed me to the shim (shell script) that rbenv uses to execute the version of rspec installed under the current version of Ruby. When I configured launch.json with that path rdebug-ide didn't like the shim. I assume it was expecting the executable.
So, I ran rbenv which rspec and got the actual path to the executable. Once I plugged that into launch.json it worked fine. Of course, if I change the version of Ruby I'm running, I'll have to update the file to point to the version of RSpec installed under the new version of Ruby.
Given the prevalence of Ruby version managers among the community, I would think ruby-debug-ide would have considered this. Perhaps it's worth an issue on their GitHub: https://github.com/ruby-debug/ruby-debug-ide.
I added a preLaunchTask to launch rdebug-ide server then looked for a pattern before attaching the debugger.
I used the focus flag for controlling which tests are run or not. Am able to set breakpoints in main script files as well as *_spec.rb files.
Gemfile:
group :test, :development do
gem "ruby-debug-ide", "~> 0.7.2"
gem "debase", "~> 0.2.4"
end
launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for rdebug-ide rspec",
"type": "Ruby",
"request": "attach",
"remoteHost": "127.0.0.1",
"remotePort": "1234",
"preLaunchTask": "run-rdebug-for-rspec",
"remoteWorkspaceRoot": "${workspaceRoot}",
"cwd": "${workspaceFolder}"
}
]
}
tasks.json
{
"version": "2.0.0",
"tasks": [{
"label": "run-rdebug-for-rspec",
"command": "bundle",
// could update these are you see fit
// my tests were located in /spec folder
"args": [
"exec","rdebug-ide",
"--host","0.0.0.0",
"--port","1234",
"--dispatcher-port","26162",
// needed to specify the full path of bundle
// can be found by `which bundle`
"--", "/usr/local/bin/bundle", "exec", "rspec", "spec/"
],
"type": "shell",
"isBackground": true,
// this will look for a pattern to attach to rdebug server
// attaching to the server will start running the tests
"problemMatcher": [
{
"pattern": [
{
"regexp": ".",
"file": 1,
"location": 2,
"message": 3
}
],
"background": {
"activeOnStart": true,
// once server is up and running it'll display something like:
// Fast Debugger (ruby-debug-ide 0.7.2, debase 0.2.4.1, file filtering is supported) listens on 0.0.0.0:1234
"beginsPattern": "^Fast Debugger.*1234$",
"endsPattern": ".",
}
}
],
// open up a new task window everytime
// if set to default `shared` then previous task window needs to be closed
// otherwise, was having issues getting patternMatcher to work
// and for rdebug to attach within a shared terminal on successive runs, or restarts.
"presentation": {
"panel": "new"
}
}]
}
While the answer above may work, there will be problems as soon as you upgrade your ruby version because the paths are hard coded.
Here is a less brittle approach that should be able to survive a version upgrade without any problem.
I'm on ruby 3.0.3, managed by rvm on mac osx.
Gemfile includes:
group :development do
gem 'ruby-debug-ide'
gem 'debase', "~> 0.2.5.beta2"
end
(the stable version of debase didn't support ruby v3, hence the beta)
Launch config use the GEM_HOME environment variable to specify the rspec binary (vscode default configuration puts this in workspace root for some reason):
{
"name": "RSpec - all",
"type": "Ruby",
"request": "launch",
"program": "${env:GEM_HOME}/bin/rspec",
"args": [
"-I",
"${workspaceRoot}"
]
}
I've been learning Ruby and now Rails.
I know in VS Code you configure the debugger with the following config
{
"name": "Debug Ruby",
"type": "Ruby",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "${file}",
},
It works just like ruby xxx.rb and pauses at breakpoints.
But I want to be able to do the same for any file in my rails project. For example, I just wrote a model user.rb for my project and i want to test and debug some functions.I tried the following:
{
"name": "Rails run",
"type": "Ruby",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "${workspaceRoot}/bin/rails",
"args": [
"runner",
"${file}"
]
},
but this wont stop at the breakpoints. there's also rails server option but that's for running the whole app but i just want to test&debug one single piece of code.
I think it doesnt work because rdebug doesnt attach to any subprocesses that the runner spins up to run the script. You could try launching the debugger directly from the ruby file you want the runner to use. You'd need to add an attach use-case in the debugger options:
For example:
.vscode/launch.json:
{
"name" : "Attach to rdebug-ide",
"type": "Ruby",
"request": "attach",
"cwd": "${workspaceRoot}",
"remoteHost": "127.0.0.1",
"remotePort": "1234",
"remoteWorkspaceRoot": "${workspaceRoot}"
},
Than in xxx.rb add the following to the top of the file:
require 'ruby-debug-ide'
require 'resource-struct'
options = ResourceStruct::FlexStruct.new({
host: '127.0.0.1',
port: '1234'
})
### Anything above this line will get run twice
Debugger.debug_program(options) unless Debugger.started?
### Rest of code you want to debug
Next run rails r xxx.rb it displays something like:
Fast Debugger (ruby-debug-ide 0.7.3, debase 0.2.4.1, file filtering is supported) listens on 127.0.0.1:1234
Lastly attached your debugger.
I have succesfully installed rvm, ruby and rails on the ubuntu subsystem on windows 10.
Now I'm trying to use the debugger on vs code for windows, but I can't find a way to do so. On my linux machine I use:
{
"name": "Rails server",
"type": "Ruby",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "${workspaceRoot}/bin/rails",
"useBundler": true,
"pathToBundler": "/home/user/.rvm/gems/ruby-2.3.1/wrappers/bundle",
"showDebuggerOutput": true,
"pathToRDebugIDE": "/home/user/.rvm/gems/ruby-2.3.1/bin/rdebug-ide",
"args": [
"server"
]
}
I tried pointing the path to the linux subsystem (%localappdata%\Lxss\home\user\.rvm...) but it doesn't work, as windows doesn't see this path.
Has anyone been able to succesfully use rdebug on linux subsytem?
How do I set up the debugger in launch.json?
Currently, I have
{
"version": "0.1.0",
"configurations": [
{
// Name of configuration
// Appears in the launch configuration drop down menu.
"name": "Launch Lukecxu",
"request": "launch",
"cwd": "/Users/lukexu/lukecxu",
"type": "node",
// Automatically stop program after launch.
"stopOnEntry": true,
"program": "${workspaceRoot}"
}
]
}
I found some of this online but it's not working. It said I should have "type" as mono but when I set it has mono it said type not supported.
For my system settings I did brew install mono and I also have ionide installed.
Right now I can't click the gutter to set any break points and when I hit F5 it says "Cannot launch program '/Users/lukexu/lukecxu'; configuring source maps might help."
Is there a tutorial to set up F# debugger in VSCode?
I think that you need to install mono debug extension
After you've installed extension following configuration should work:
{
"version": "0.1.0",
"configurations": [
{
// optional "preLaunchTask": "Build" - some way of building your application.
"externalConsole": true,
"name": "Launch",
"type": "mono",
// Workspace relative or absolute path to the program.
"program": "${workspaceRoot}/bin/myapp/myapp.exe",
"stopOnEntry": true
},
{
"name": "Attach",
"request": "attach",
"type": "mono",
"address": "localhost",
"port": 55555
}
]
}