From ee67773ba92f37ec5ad06b3e117cda017acc114d Mon Sep 17 00:00:00 2001 From: Fredrik Averpil Date: Sat, 15 Jun 2024 18:17:51 +0200 Subject: [PATCH] refactor: adapter options --- lua/neotest-golang/init.lua | 27 ++------------------------- lua/neotest-golang/options.lua | 32 +++++++++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/lua/neotest-golang/init.lua b/lua/neotest-golang/init.lua index 7f6e81ef..55ba87cc 100644 --- a/lua/neotest-golang/init.lua +++ b/lua/neotest-golang/init.lua @@ -145,34 +145,11 @@ function M.Adapter.results(spec, result, tree) ) end +--- Adapter options. setmetatable(M.Adapter, { __call = function(_, opts) - return M.Adapter.setup(opts) + return options.setup(opts) end, }) -M.Adapter.setup = function(opts) - opts = opts or {} - if opts.args or opts.dap_go_args then - -- temporary warning - vim.notify( - "Please update your config, the arguments/opts have changed for neotest-golang.", - vim.log.levels.WARN - ) - end - if opts.go_test_args then - if opts.go_test_args then - options._go_test_args = opts.go_test_args - end - if opts.dap_go_enabled then - options._dap_go_enabled = opts.dap_go_enabled - if opts.dap_go_opts then - options._dap_go_opts = opts.dap_go_opts - end - end - end - - return M.Adapter -end - return M.Adapter diff --git a/lua/neotest-golang/options.lua b/lua/neotest-golang/options.lua index 91969ade..943252c5 100644 --- a/lua/neotest-golang/options.lua +++ b/lua/neotest-golang/options.lua @@ -1,6 +1,6 @@ --- These are the default options for neotest-golang. You can override them by --- providing them as arguments to the Adapter function. See the README for mode --- details and examples. +--- These are the default options for neotest-golang. You can override them by +--- providing them as arguments to the Adapter function. See the README for mode +--- details and examples. local M = {} @@ -22,4 +22,30 @@ M._dap_go_enabled = false --- @type table M._dap_go_opts = {} +--- Option setup function. This is what you call when setting up the adapter. +--- @param opts table +function M.setup(opts) + opts = opts or {} + if opts.args or opts.dap_go_args then + -- temporary warning + vim.notify( + "Please update your config, the arguments/opts have changed for neotest-golang.", + vim.log.levels.WARN + ) + end + if opts.go_test_args then + if opts.go_test_args then + M._go_test_args = opts.go_test_args + end + if opts.dap_go_enabled then + M._dap_go_enabled = opts.dap_go_enabled + if opts.dap_go_opts then + M._dap_go_opts = opts.dap_go_opts + end + end + end + + return M.Adapter +end + return M