Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lua/dap/session.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,14 @@ local function start_debugging(self, request)
adapter = coroutine.yield()
end

-- Prefer connecting to root server again if it is of type server and
-- the new adapter would have an executable.
-- Spawning a new executable is likely the wrong thing to do
if self.adapter.type == "server" and adapter.executable then
adapter = vim.deepcopy(self.adapter)
adapter.executable = nil
end

local expected_types = {"executable", "server"}
if type(adapter) ~= "table" or not vim.tbl_contains(expected_types, adapter.type) then
local msg = "Invalid adapter definition. Expected a table with type `executable` or `server`: "
Expand Down
14 changes: 10 additions & 4 deletions tests/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ end

function M.spawn(opts)
opts = opts or {}
local server = uv.new_tcp()
local server = assert(uv.new_tcp())
local host = '127.0.0.1'
local spy = {
requests = {},
Expand All @@ -126,16 +126,22 @@ function M.spawn(opts)
seq = 0,
handlers = {},
spy = spy,
num_connected = 0,
}
setmetatable(client, {__index = Client})
server:listen(128, function(err)
assert(not err, err)
local socket = uv.new_tcp()
client.num_connected = client.num_connected + 1
local socket = assert(uv.new_tcp())
client.socket = socket
server:accept(socket)
socket:read_start(rpc.create_read_loop((function(body)
local function on_chunk(body)
client:handle_input(body)
end)))
end
local function on_eof()
client.num_connected = client.num_connected - 1
end
socket:read_start(rpc.create_read_loop(on_chunk, on_eof))
end)
return {
client = client,
Expand Down
32 changes: 31 additions & 1 deletion tests/sessions_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describe('sessions', function()
}
run_and_wait_until_initialized(conf1, srv1)
srv1.client:send_request("startDebugging", {
request = "laucnh",
request = "launch",
configuration = {
type = "dummy2",
name = "Subprocess"
Expand All @@ -88,4 +88,34 @@ describe('sessions', function()
wait(function() return vim.tbl_count(dap.session().children) == 0 end)
assert.are.same({}, dap.session().children)
end)

it("startDebugging connects to root adapter if type server with executable", function()
local conf1 = {
type = 'dummy1',
request = 'launch',
name = 'Launch file 1',
}
local session = run_and_wait_until_initialized(conf1, srv1)
assert.are.same(1, srv1.client.num_connected)
dap.adapters.dummy2 = {
type = "server",
executable = {
command = "echo",
args = {"not", "used"},
}
}
srv1.client:send_request("startDebugging", {
request = "launch",
configuration = {
type = "dummy2",
name = "Subprocess"
}
})
wait(
function() return vim.tbl_count(session.children) == 1 end,
function() return dap.session() end
)
assert.are.same(2, srv1.client.num_connected)
dap.terminate()
end)
end)