Search code examples
ruby-on-railsvimpassengervimspector

Configuring vimspector with ruby on rails app running passenger


My question is how do i get vimspector running with a ruby on rails app running passenger (I think)

I'm trying to set up vimspector with some ruby on rails projects I'm working on. Basically the problem is that vimspector doesn't stop at breakpoints in some apps. the apps are using passenger. In a very basic sample app vimspector works fine, but not in the ones where i actually need to debug.

Description:

when i call vimspector#Launch all the splits/windows come up, and a passenger application server gets launched. I don't work alone on some projects so i cannot really change this to another one.

I set some breakpoints and do actions that should stop at them but they run through like without a debugger. Also nothing except for threads running and the console output of the rails server shows up in the splits. In my processes 2 processes show up. Once the Passenger Ruby app and once a node process going to my cust_vscode-ruby directory which is needed for the debugger. The node process has the subprocess rdebug-ide and rdebug-ide has passenger start.

As vimspector works fine with the sample rails app, I don't think its a problem of the install or something like that.

I tried switching to attach but when configuring it for attach i get an endless loading without getting a timeout in the browser. the terminal window where i run rdebug-ide starts of without any repsonse, i launch vimspector and the server is being booted up. It stops at this however and never goes past booting Run rails server -h for more startup options. After which passenger normally starts up. With switching to attach mode only the rdebug controlled rails server shows up in my processes.

I think this should be possible as i'm usind ruby-debug-ide which is being used by RubyMine on which i could debug the apps running passenger just fine. I'm pretty sure that is has to do with passenger as calling it up in launch config leads to it escaping and using attach config leads to it blocking the rails server boot. But I don't know how to fix it.

.vimspector.json same for both sample app and actual app :

{
    "configurations": {
        "rails": {
            "adapter": "cust_vscode-ruby",
            "default": true,
            "configuration": {
                "name": "Debug Rails server",
                "type": "Ruby",
                "request": "launch",
                "cwd": "${workspaceRoot}",
                "pathToBundler": "/Users/username/.rvm/rubies/ruby-version/bin/bundler",
                "pathToRDebugIDE": "/Users/username/.rvm/gems/ruby-version/gems/ruby-debug-ide-0.7.3",
                "program": "${workspaceRoot}/bin/rails",
                "args": [
                    "server"
                ]
            }
        }
    }
}

vimspector configuration output

Vimspector Debug Info
--------------------------------------------------------------------------------
ConnectionType: job
Adapter: 
--------------------------------------------------------------------------------
{
  "command": [
    "node",
    "/Users/username/.vim/plugged/vimspector/gadgets/macos/cust_vscode-ruby/dist/debugger/main.js"
  ],
  "configuration": {
    "cwd": "/Users/username/Folder/app-name",
    "showDebugOutput": false,
    "trace": false
  },
  "name": "vscode-ruby-debug",
  "env": {},
  "cwd": "/Users/username/Folder/app-name"
}
--------------------------------------------------------------------------------
Configuration: 
--------------------------------------------------------------------------------
{
  "adapter": "cust_vscode-ruby",
  "default": true,
  "configuration": {
    "name": "Debug Rails server",
    "type": "Ruby",
    "request": "launch",
    "cwd": "/Users/username/Folder/app-name",
    "pathToBundler": "/Users/username/.rvm/rubies/ruby-version/bin/bundler",
    "pathToRDebugIDE": "/Users/username/.rvm/gems/ruby-version/gems/ruby-debug-ide-0.7.3",
    "program": "/Users/username/Folder/app-name/bin/rails",
    "args": [
      "server"
    ]
  }
}
--------------------------------------------------------------------------------
API Prefix: 
Launch/Init: True / True
Workspace Root: /Users/username/Folder/app-name
Launch Config: 
--------------------------------------------------------------------------------
{
  "cwd": "/Users/username/Folder/app-name",
  "showDebugOutput": false,
  "trace": false,
  "name": "Debug Rails server",
  "type": "Ruby",
  "request": "launch",
  "pathToBundler": "/Users/username/.rvm/rubies/ruby-version/bin/bundler",
  "pathToRDebugIDE": "/Users/username/.rvm/gems/ruby-version/gems/ruby-debug-ide-0.7.3",
  "program": "/Users/username/Folder/app-name/bin/rails",
  "args": [
    "server"
  ]
}
--------------------------------------------------------------------------------
Server Capabilities: 
--------------------------------------------------------------------------------
{
  "supportsConfigurationDoneRequest": true,
  "supportsConditionalBreakpoints": true
}
--------------------------------------------------------------------------------
Line Breakpoints: 
--------------------------------------------------------------------------------
{
  "/Users/username/Folder/app-name/app/controllers/.../somethings_controller.rb": [
    {
      "state": "ENABLED",
      "line": 83,
      "options": {},
      "sign_id": 1,
      "server_bp": {
        "verified": true,
        "line": 83,
        "id": 1
      }
    }
  ]
}
--------------------------------------------------------------------------------
Func Breakpoints: 
--------------------------------------------------------------------------------
[]
--------------------------------------------------------------------------------
Ex Breakpoints: 
None

Solution

  • so i got it to work not with passenger itself.

    i changed my vimspector config to the following, switching up some paths to the used binaries by trial and error (i think the one that matters is calling the rails binary in the project root). The important thing is to call in the args server -u puma. Make sure to write each part of the command as a single argument. puma being the default rails server (i found it to be in my sample app), so this gets picked up by rdebug-ide and debase.

    { 
        "configurations": { 
                "rails": { 
                        "adapter": "cust_vscode-ruby", 
                        "default": true, 
                        "configuration": { 
                                "name": "Debug Rails server", 
                                "type": "Ruby", 
                                "request": "launch", 
                                "cwd": "${workspaceRoot}", 
                                "pathToBundler": "/Users/username/.rvm/rubies/ruby-RUBYVERSION/bin/bundler", 
                                "pathToRDebugIDE": "/Users/username/.rvm/gems/ruby-RUBYVERSION/gems/ruby-debug-ide-RUBYDEBUGIDEVERSION", 
                                "program": "${workspaceRoot}/bin/rails", 
                                "args": [ 
                                        "server", "-u", "puma" 
                                ] 
                        } 
                } 
        } 
    

    }

    There are some options I found for using passenger, it probably has to do something with writing the config as attach.

    What seemed closest (but it doesn't work) to the answer seemed to copy the rubymine config that calls:

    /bin/bash -c "~/.rvm/bin/rvm _RUBYVERSION_ do ~/.rvm/rubies/ruby-_RUBYVERSION_/bin/ruby ~/.rvm/gems/ruby-_VERSION_/gems/ruby-debug-ide-_RUBYDEBUG-IDEVERSION_/bin/rdebug-ide --key-value --disable-int-handler --evaluation-timeout 10 --evaluation-control --time-limit 100 --memory-limit 0 --rubymine-protocol-extensions --port 42371 --host 0.0.0.0 --dispatcher-port 38403 -- ~/Folder/project/bin/rails server -b 0.0.0.0 -p 3000 -e development"
    

    I think a point where it could be failing, and why it's not working is that passenger needs to be set to allow debugging (PassengerDebugger on), although i might just be confusing everything here. However this passenger option is reserved for the Enterprise version (https://www.phusionpassenger.com/library/admin/apache/debugging_console/ruby/). Where this left me off was i launched this debug config but couldn't connect to the socket. Maybe this is to some security measure i made to tight for my own good on my system or more likely a fault in the config.

    I think it's possible to attach to the passenger server properly somehow some ideas could maybe be found here but i didn't get anywhere with them. https://mondotondo.com/2012/08/23/how-to-remotely-debug-rails-in-apache-passenger-rubymine/ How can I get ruby-debug-ide to work?

    If you are struggeling like me with this, hang in there you will get it some day!