From 9959cb55a5e42f55cb9d98f8b4534512cb869bfe Mon Sep 17 00:00:00 2001 From: mcoqzeug Date: Sun, 22 Sep 2024 21:07:53 +0800 Subject: [PATCH] set cwd for dlv based on program 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 --- lua/dap-go.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lua/dap-go.lua b/lua/dap-go.lua index 6e125a9..f808059 100644 --- a/lua/dap-go.lua +++ b/lua/dap-go.lua @@ -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