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 Sep 22, 2024
1 parent 5511788 commit 7a44841
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lua/dap-go.lua
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ local function setup_delve_adapter(dap, config)
}

dap.adapters.go = function(callback, client_config)
local program = client_config.program
local path = require("plenary.path")
local program_path = path:new(program)

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

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

0 comments on commit 7a44841

Please sign in to comment.