Skip to content

Commit

Permalink
Conditionally run command
Browse files Browse the repository at this point in the history
And allow for attaching to existing debugging session
  • Loading branch information
tttffff committed Apr 20, 2024
1 parent 22412e5 commit 57854a7
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions lua/dap-ruby.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,26 @@ end

local function setup_ruby_adapter(dap)
dap.adapters.ruby = function(callback, config)
local handle
local pid_or_err
local waiting = config.waiting or 500

vim.env.RUBY_DEBUG_OPEN = true
vim.env.RUBY_DEBUG_HOST = config.server
vim.env.RUBY_DEBUG_PORT = config.port

local opts = { args = config.args }
if config.command then
local handle
local pid_or_err
local opts = { args = config.args }
handle, pid_or_err = vim.loop.spawn(config.command, opts, function(code)
handle:close()
if code ~= 0 then
assert(handle, "rdbg exited with code: " .. tostring(code))
print("rdbg exited with code", code)
end
end)

handle, pid_or_err = vim.loop.spawn(config.command, opts, function(code)
handle:close()
if code ~= 0 then
assert(handle, "rdbg exited with code: " .. tostring(code))
print("rdbg exited with code", code)
end
end)
assert(handle, "Error running rgdb: " .. tostring(pid_or_err))
end

assert(handle, "Error running rgdb: " .. tostring(pid_or_err))

Expand Down Expand Up @@ -111,6 +114,18 @@ local function setup_ruby_configuration(dap)
localfs = true,
waiting = 1000,
},
{
type = "ruby",
name = "attach existing",
request = "attach",
port = 38698,
server = "127.0.0.1",
options = {
source_filetype = "ruby",
},
localfs = true,
waiting = 1000,
},
}
end

Expand Down

0 comments on commit 57854a7

Please sign in to comment.