all repos

gopher.nvim @ e0a3e70e484f09ac550d78304de9ad2d675d374d

Minimalistic plugin for Go development
3 files changed, 36 insertions(+), 4 deletions(-)
add ability for setting custom tools options (#44)

* feat(gotests): add custom templates support

* feat(struct_tags): add support for custom `transform` option
Author: Smirnov Oleksandr ss2316544@gmail.com
Committed by: GitHub noreply@github.com
Committed at: 2023-08-17 19:13:56 +0300
Parent: 2e89cea
M lua/gopher/config.lua

@@ -1,6 +1,14 @@

---@type gopher.Config local config = {} +---@alias gopher.ConfigGoTagTransform +---| "snakecase" "GopherUser" -> "gopher_user" +---| "camelcase" "GopherUser" -> "gopherUser" +---| "lispcase" "GopherUser" -> "gopher-user" +---| "pascalcase" "GopherUser" -> "GopherUser" +---| "titlecase" "GopherUser" -> "Gopher User" +---| "keep" keeps the original field name + ---@class gopher.Config local default_config = { ---@class gopher.ConfigCommand

@@ -11,6 +19,19 @@ gotests = "gotests",

impl = "impl", 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, + }, + ---@class gopher.ConfigGoTag + gotag = { + ---@type gopher.ConfigGoTagTransform + transform = "snakecase", }, }
M 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
M lua/gopher/struct_tags.lua

@@ -1,6 +1,6 @@

local ts_utils = require "gopher._utils.ts" local r = require "gopher._utils.runner" -local c = require("gopher.config").commands +local c = require "gopher.config" local struct_tags = {} local function modify(...)

@@ -12,6 +12,7 @@ end

-- stylua: ignore local cmd_args = { + "-transform", c.gotag.transform, "-format", "json", "-file", fpath, "-w"

@@ -38,7 +39,7 @@ if #arg == 1 and arg[1] ~= "-clear-tags" then

table.insert(cmd_args, "json") end - local output = r.sync(c.gomodifytags, { + local output = r.sync(c.commands.gomodifytags, { args = cmd_args, on_exit = function(data, status) if not status == 0 then