From e33c0f133921158599f39bd44bfe89fe86b69031 Mon Sep 17 00:00:00 2001 From: Gustavo Ferreira Date: Mon, 17 Jun 2024 18:13:33 +0100 Subject: [PATCH 1/6] feat: add verbosity option to running closest test --- lua/dap-go.lua | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/lua/dap-go.lua b/lua/dap-go.lua index a365043..8b9c572 100644 --- a/lua/dap-go.lua +++ b/lua/dap-go.lua @@ -4,6 +4,7 @@ local M = { last_testname = "", last_testpath = "", test_buildflags = "", + test_verbose = false, } local default_config = { @@ -15,6 +16,9 @@ local default_config = { build_flags = "", detached = true, }, + tests = { + verbose = false, + }, } local function load_module(module_name) @@ -127,14 +131,16 @@ end function M.setup(opts) local config = vim.tbl_deep_extend("force", default_config, opts or {}) M.test_buildflags = config.delve.build_flags + M.test_verbose = config.tests.verbose local dap = load_module("dap") setup_delve_adapter(dap, config) setup_go_configuration(dap, config) end -local function debug_test(testname, testpath, build_flags) +local function debug_test(testname, testpath, build_flags, extra_args) local dap = load_module("dap") - dap.run({ + + local config = { type = "go", name = testname, request = "launch", @@ -142,7 +148,13 @@ local function debug_test(testname, testpath, build_flags) program = testpath, args = { "-test.run", "^" .. testname .. "$" }, buildFlags = build_flags, - }) + } + + if not vim.tbl_isempty(extra_args) then + table.move(extra_args, 1, #extra_args, #config.args + 1, config.args) + end + + dap.run(config) end function M.debug_test() @@ -158,7 +170,13 @@ function M.debug_test() local msg = string.format("starting debug session '%s : %s'...", test.package, test.name) vim.notify(msg) - debug_test(test.name, test.package, M.test_buildflags) + + local extra_args = {} + if M.test_verbose then + extra_args = { "-test.v" } + end + + debug_test(test.name, test.package, M.test_buildflags, extra_args) return true end @@ -174,7 +192,13 @@ function M.debug_last_test() local msg = string.format("starting debug session '%s : %s'...", testpath, testname) vim.notify(msg) - debug_test(testname, testpath, M.test_buildflags) + + local extra_args = {} + if M.test_verbose then + extra_args = { "-test.v" } + end + + debug_test(testname, testpath, M.test_buildflags, extra_args) return true end From 824c7167d601c9c963c39e77987a5da2e7f8818a Mon Sep 17 00:00:00 2001 From: Gustavo Ferreira Date: Mon, 17 Jun 2024 18:16:10 +0100 Subject: [PATCH 2/6] update readme file --- README.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 06719fb..0b70443 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,11 @@ lua require('dap-go').setup { -- the current working directory. cwd = nil, }, + -- options related to running closest test + tests = { + -- enables verbosity when running the test. + verbose = false, + }, } ``` @@ -97,11 +102,12 @@ lua require('dap-go').setup { ### Debugging individual tests - To debug the closest method above the cursor use you can run: + - `:lua require('dap-go').debug_test()` Once a test was run, you can simply run it again from anywhere: + - `:lua require('dap-go').debug_last_test()` It is better to define a mapping to invoke this command. See the mapping section below. @@ -119,6 +125,7 @@ It is better to define a mapping to invoke this command. See the mapping section ### Debugging with dlv in headless mode 1. Register a new option to attach to a remote debugger: + ```lua lua require('dap-go').setup { dap_configurations = { @@ -131,10 +138,13 @@ lua require('dap-go').setup { }, } ``` + 1. Start `dlv` in headless mode. You can specify subcommands and flags after `--`, e.g., + ```sh dlv debug -l 127.0.0.1:38697 --headless ./main.go -- subcommand --myflag=xyz ``` + 1. Call `:lua require('dap').continue()` to start debugging. 1. Select the new registered option `Attach remote`. From 8e2bb311e02b1b450f366d0bf266d68d1adc9a95 Mon Sep 17 00:00:00 2001 From: Gustavo Ferreira Date: Mon, 17 Jun 2024 18:18:35 +0100 Subject: [PATCH 3/6] undo markdown formatting --- README.md | 6 ------ 1 file changed, 6 deletions(-) diff --git a/README.md b/README.md index 0b70443..382d82e 100644 --- a/README.md +++ b/README.md @@ -103,11 +103,9 @@ lua require('dap-go').setup { ### Debugging individual tests To debug the closest method above the cursor use you can run: - - `:lua require('dap-go').debug_test()` Once a test was run, you can simply run it again from anywhere: - - `:lua require('dap-go').debug_last_test()` It is better to define a mapping to invoke this command. See the mapping section below. @@ -125,7 +123,6 @@ It is better to define a mapping to invoke this command. See the mapping section ### Debugging with dlv in headless mode 1. Register a new option to attach to a remote debugger: - ```lua lua require('dap-go').setup { dap_configurations = { @@ -138,13 +135,10 @@ lua require('dap-go').setup { }, } ``` - 1. Start `dlv` in headless mode. You can specify subcommands and flags after `--`, e.g., - ```sh dlv debug -l 127.0.0.1:38697 --headless ./main.go -- subcommand --myflag=xyz ``` - 1. Call `:lua require('dap').continue()` to start debugging. 1. Select the new registered option `Attach remote`. From 020805eec5d0c77ce7567972354f99c5b93b9f97 Mon Sep 17 00:00:00 2001 From: Gustavo Ferreira Date: Mon, 17 Jun 2024 18:19:51 +0100 Subject: [PATCH 4/6] undo markdown formatting --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 382d82e..7964189 100644 --- a/README.md +++ b/README.md @@ -102,6 +102,7 @@ lua require('dap-go').setup { ### Debugging individual tests + To debug the closest method above the cursor use you can run: - `:lua require('dap-go').debug_test()` From 29fb61e6c19ebb50fb133f1302a92fc0293135b0 Mon Sep 17 00:00:00 2001 From: Gustavo Ferreira Date: Tue, 9 Jul 2024 22:48:01 +0100 Subject: [PATCH 5/6] updated nvim docs with new functionality --- doc/nvim-dap-go.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/doc/nvim-dap-go.txt b/doc/nvim-dap-go.txt index b9883ee..aa8c01b 100644 --- a/doc/nvim-dap-go.txt +++ b/doc/nvim-dap-go.txt @@ -95,6 +95,11 @@ The example bellow shows all the possible configurations: -- otherwise the dlv server creation will fail. detached = true }, + -- options related to running closest test + tests = { + -- enables verbosity when running the test. + verbose = false, + }, } < From ecc70b3a96edca21d6a6be1bb4db2b03471d85b0 Mon Sep 17 00:00:00 2001 From: LeoLuz Date: Thu, 18 Jul 2024 22:51:10 -0400 Subject: [PATCH 6/6] fix merge --- lua/dap-go.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/dap-go.lua b/lua/dap-go.lua index 6795782..cfded30 100644 --- a/lua/dap-go.lua +++ b/lua/dap-go.lua @@ -147,7 +147,7 @@ local function setup_go_configuration(dap, configs) if config.type == "go" then table.insert(dap.configurations.go, config) end - end_delve_adapter(dap, internal_global_confi + end end function M.setup(opts)