Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use build flags for delve in dap-go config #178

Merged
merged 2 commits into from
Sep 8, 2024
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
28 changes: 26 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -517,9 +517,33 @@ feature... 🙈

If you need to set build tags (like e.g. `-tags debug` or `-tags "tag1 tag2"`),
you need to provide these arguments both in the `go_test_args` and
`go_list_args` adapter options.
`go_list_args` adapter options. If you want to be able to debug, you also need
to set `dap_go_opts`. Full example:

> !TIP
```lua
return {
{
"nvim-neotest/neotest",
config = function()
require("neotest").setup({
adapters = {
require("neotest-golang")({
go_test_args = { "-count=1", "-tags=integration" },
go_list_args = { "-tags=integration" },
dap_go_opts = {
delve = {
build_flags = { "-tags=integration" },
},
},
}),
},
})
end,
},
}
```

> [!TIP]
>
> Depending on how you have Neovim setup, you can define this on a per-project
> basis by placing a `.lazy.lua` with overrides in the project. This requires
Expand Down
11 changes: 11 additions & 0 deletions lua/neotest-golang/features/dap/init.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
--- DAP setup related functions.

local options = require("neotest-golang.options")
local logger = require("neotest-golang.logging")

local M = {}

Expand All @@ -13,10 +14,15 @@ function M.setup_debugging(cwd)
dap_go_opts.delve = {}
end
dap_go_opts.delve.cwd = cwd
logger.debug({ "Provided dap_go_opts for DAP: ", dap_go_opts })
require("dap-go").setup(dap_go_opts)

-- reset nvim-dap-go (and cwd) after debugging with nvim-dap
require("dap").listeners.after.event_terminated["neotest-golang-debug"] = function()
logger.debug({
"Resetting provided dap_go_opts for DAP: ",
dap_go_opts_original,
})
require("dap-go").setup(dap_go_opts_original)
end
end
Expand All @@ -34,6 +40,11 @@ function M.get_dap_config(test_name_regex)
args = { "-test.run", test_name_regex },
}

local dap_go_opts = options.get().dap_go_opts or {}
if dap_go_opts.delve ~= nil and dap_go_opts.delve.build_flags ~= nil then
dap_config.buildFlags = dap_go_opts.delve.build_flags
end

return dap_config
end

Expand Down
Loading