From 4217211912fe00750ad4fc0288b6c25e8c41c892 Mon Sep 17 00:00:00 2001 From: Smirnov Oleksandr Date: Thu, 17 Aug 2023 13:04:51 +0300 Subject: [PATCH] feat(gotests): add custom templates support --- lua/gopher/config.lua | 8 ++++++++ lua/gopher/gotests.lua | 14 ++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lua/gopher/config.lua b/lua/gopher/config.lua index 68b29e6..2c12de5 100644 --- a/lua/gopher/config.lua +++ b/lua/gopher/config.lua @@ -12,6 +12,14 @@ local default_config = { iferr = "iferr", dlv = "dlv", }, + ---@class gopjer.ConfigGotests + gotests = { + -- gotests doesn't have template named "default" so this plugin uses "default" to set the default template + template = "default", + -- path to a directory containing custom test code templates + ---@type string|nil + template_dir = nil, + }, } ---@type gopher.Config diff --git a/lua/gopher/gotests.lua b/lua/gopher/gotests.lua index 942fab3..f98b365 100644 --- a/lua/gopher/gotests.lua +++ b/lua/gopher/gotests.lua @@ -1,4 +1,4 @@ -local c = require("gopher.config").commands +local c = require "gopher.config" local ts_utils = require "gopher._utils.ts" local r = require "gopher._utils.runner" local u = require "gopher._utils" @@ -6,10 +6,20 @@ local gotests = {} ---@param args table local function add_test(args) + if c.gotests.template_dir then + table.insert(args, "-template_dir") + table.insert(args, c.gotests.template_dir) + end + + if c.gotests.template ~= "default" then + table.insert(args, "-template") + table.insert(args, c.gotests.template) + end + table.insert(args, "-w") table.insert(args, vim.fn.expand "%") - return r.sync(c.gotests, { + return r.sync(c.commands.gotests, { args = args, on_exit = function(data, status) if not status == 0 then