Skip to content

Commit

Permalink
refactor: options and defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikaverpil committed Jun 18, 2024
1 parent ee6cd4c commit b07ba4a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 38 deletions.
2 changes: 1 addition & 1 deletion lua/neotest-golang/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ end
--- Adapter options.
setmetatable(M.Adapter, {
__call = function(_, opts)
return options.setup(opts)
M.Adapter.options = options.setup(opts)
end,
})

Expand Down
66 changes: 29 additions & 37 deletions lua/neotest-golang/options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,42 @@
--- providing them as arguments to the Adapter function. See the README for mode
--- details and examples.

local M = {}
local Opts = {}

--- Arguments to pass into `go test`. Will be combined with arguments required
--- for neotest-golang to work and execute the expected test(s).
--- @type table
M._go_test_args = {
"-v",
"-race",
"-count=1",
"-timeout=60s",
}
--- Create a new options object.
function Opts:new(opts)
self.go_test_args = opts.go_test_args
or {
"-v",
"-race",
"-count=1",
"-timeout=60s",
}
self.dap_go_enabled = opts.dap_go_enabled or false
self.dap_go_opts = opts.dap_go_opts or {}
end

--- Whether to enable nvim-dap-go.
--- @type boolean
M._dap_go_enabled = false
--- A convenience function to get the current options.
function Opts:get()
return {
go_test_args = self.go_test_args,
dap_go_enabled = self.dap_go_enabled,
dap_go_opts = self.dap_go_opts,
}
end

--- Options to pass into dap-go.setup.
--- @type table
M._dap_go_opts = {}
local M = {}

--- Option setup function. This is what you call when setting up the adapter.
--- @param opts table
--- Set up the adapter.
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
Opts:new(opts)
return M.options
end

return M.Adapter
--- Get the adapter configuration.
function M.get()
return Opts:get()
end

return M

0 comments on commit b07ba4a

Please sign in to comment.