diff --git a/README.md b/README.md index de5303dd4..0fdef2c8c 100644 --- a/README.md +++ b/README.md @@ -627,6 +627,15 @@ Here is a sample [launch.json](https://github.com/ray-x/go.nvim/blob/master/play ### Load Env file - GoEnv {filename} By default load .env file in current directory, if you want to load other file, use {filename} option +- Alternatively, you can specify an `dap_enrich_config` function, to modify the selected launch.json configuration on the fly, + as suggested by https://github.com/mfussenegger/nvim-dap/discussions/548#discussioncomment-8778225: + ```lua + dap_enrich_config = function(config, on_config) + local final_config = vim.deepcopy(finalConfig) + final_config.env['NEW_ENV_VAR'] = 'env-var-value' + on_config(final_config) + end + ``` ### Generate return value @@ -852,6 +861,7 @@ require('go').setup({ dap_port = 38697, -- can be set to a number, if set to -1 go.nvim will pick up a random port dap_timeout = 15, -- see dap option initialize_timeout_sec = 15, dap_retries = 20, -- see dap option max_retries + dap_enrich_config = nil, -- see dap option enrich_config build_tags = "tag1,tag2", -- set default build tags textobjects = true, -- enable default text objects through treesittter-text-objects test_runner = 'go', -- one of {`go`, `dlv`, `ginkgo`, `gotestsum`} diff --git a/lua/go.lua b/lua/go.lua index e223f9e6c..2f78db3e8 100644 --- a/lua/go.lua +++ b/lua/go.lua @@ -145,6 +145,7 @@ _GO_NVIM_CFG = { dap_debug_vt = { enabled = true, enabled_commands = true, all_frames = true }, -- bool|table put your dap-virtual-text setup here set to false to disable dap_port = 38697, -- can be set to a number or -1 so go.nvim will pickup a random port dap_timeout = 15, -- see dap option initialize_timeout_sec = 15, + dap_enrich_config = nil, -- see dap option enrich_config dap_retries = 20, -- see dap option max_retries build_tags = '', --- you can provide extra build tags for tests or debugger textobjects = true, -- treesitter binding for text objects diff --git a/lua/go/dap.lua b/lua/go/dap.lua index 54623d149..56e2b1326 100644 --- a/lua/go/dap.lua +++ b/lua/go/dap.lua @@ -386,7 +386,13 @@ M.run = function(...) } dap.adapters.go = function(callback, config) if config.request == 'attach' and config.mode == 'remote' and config.host then - callback({ type = 'server', host = config.host, port = config.port, options = con_options }) + callback({ + type = 'server', + host = config.host, + port = config.port, + options = con_options, + enrich_config = _GO_NVIM_CFG.dap_enrich_config, + }) return end stdout = vim.loop.new_pipe(false) @@ -443,7 +449,13 @@ M.run = function(...) stderr:read_start(onread) vim.defer_fn(function() - callback({ type = 'server', host = host, port = port, options = con_options }) + callback({ + type = 'server', + host = host, + port = port, + options = con_options, + enrich_config = _GO_NVIM_CFG.dap_enrich_config, + }) end, 1000) end