Skip to content

Commit

Permalink
fix: do not add executable to adapter in launch request
Browse files Browse the repository at this point in the history
The adapter would add the `executable` property to the adapter
regardless of whether the request was `launch` or `attach`. When
`attach` was used, it would attempt to start `dlv` on the same port that
it was attempting to configure.

This changes it so the executable is not added if `attach` is used and
adds some protection code to prevent the random port assignment from
being used with the attach configuration (where it wouldn't work
anyway).
  • Loading branch information
jsternberg committed Jun 26, 2024
1 parent a0c5a2b commit 4d6cc50
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions lua/dap-go.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,32 @@ local function setup_delve_adapter(dap, config)
local args = { "dap", "-l", "127.0.0.1:" .. config.delve.port }
vim.list_extend(args, config.delve.args)

dap.adapters.go = {
type = "server",
port = config.delve.port,
executable = {
command = config.delve.path,
args = args,
detached = config.delve.detached,
cwd = config.delve.cwd,
},
options = {
initialize_timeout_sec = config.delve.initialize_timeout_sec,
},
}
local delve = config.delve
dap.adapters.go = function(cb, config)
local adapter = {
type = "server",
port = (config.port or delve.port),
options = {
initialize_timeout_sec = delve.initialize_timeout_sec,
},
}

assert(adapter.port, "`port` is required for go configuration")
assert(
config.request ~= "attach" or adapter.port ~= "{port}",
"`port` cannot be randomly assigned when using `attach` configuration"
)

if config.request == "launch" then
adapter.executable = {
command = delve.path,
args = args,
detached = delve.detached,
cwd = delve.cwd,
}
end
cb(adapter)
end
end

local function setup_go_configuration(dap, configs)
Expand Down

0 comments on commit 4d6cc50

Please sign in to comment.