Skip to content

Commit

Permalink
set cwd for dlv based on program
Browse files Browse the repository at this point in the history
This potentially resolves #85.

vscode-go sets dlv cwd based on the value of program.

Reference: https://github.com/golang/vscode-go/blob/master/extension/src/goDebugConfiguration.ts#L545
  • Loading branch information
mcoqzeug authored and jxl committed Oct 4, 2024
1 parent 6aa8816 commit 9959cb5
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lua/dap-go.lua
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,21 @@ local function setup_delve_adapter(dap, config)
}

dap.adapters.go = function(callback, client_config)
if client_config.program ~= nil then
local program = client_config.program
local path = require("plenary.path")
local program_path = path:new(program)
local program_absolute = program_path:absolute()

client_config.program = program_absolute

if program_path:is_dir() then
delve_config.executable.cwd = program_absolute
elseif program:match("^.+(%..+)$") == ".go" then -- file extension is '.go'
delve_config.executable.cwd = tostring(program_path:parent())
end
end

if client_config.port == nil then
callback(delve_config)
return
Expand Down

0 comments on commit 9959cb5

Please sign in to comment.