From 2f07c724a5912ffb58f1b9c715016d39043a4fa8 Mon Sep 17 00:00:00 2001 From: Fredrik Averpil Date: Sat, 7 Sep 2024 06:44:56 +0200 Subject: [PATCH 1/2] feat: use build flags for delve in dap-go config --- lua/neotest-golang/features/dap/init.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lua/neotest-golang/features/dap/init.lua b/lua/neotest-golang/features/dap/init.lua index 8066180f..0fd03707 100644 --- a/lua/neotest-golang/features/dap/init.lua +++ b/lua/neotest-golang/features/dap/init.lua @@ -1,6 +1,7 @@ --- DAP setup related functions. local options = require("neotest-golang.options") +local logger = require("neotest-golang.logging") local M = {} @@ -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 @@ -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 From ae5c44f1e85675720e69f9a918d1ebfddf5b681e Mon Sep 17 00:00:00 2001 From: Fredrik Averpil Date: Sat, 7 Sep 2024 06:55:43 +0200 Subject: [PATCH 2/2] docs: update docs by mentioning setting delve build tags --- README.md | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f3156307..511cc6bd 100644 --- a/README.md +++ b/README.md @@ -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