From e2f3096a5fe6e296cb6eb6547ff738f3b1b3b114 Mon Sep 17 00:00:00 2001 From: Smirnov Oleksandr Date: Thu, 17 Aug 2023 13:32:09 +0300 Subject: [PATCH] feat(struct_tags): add support for custom `transform` option --- lua/gopher/config.lua | 13 +++++++++++++ lua/gopher/struct_tags.lua | 5 +++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lua/gopher/config.lua b/lua/gopher/config.lua index 2c12de5..f1cf2ad 100644 --- a/lua/gopher/config.lua +++ b/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 @@ -20,6 +28,11 @@ local default_config = { ---@type string|nil template_dir = nil, }, + ---@class gopher.ConfigGoTag + gotag = { + ---@type gopher.ConfigGoTagTransform + transform = "snakecase", + }, } ---@type gopher.Config diff --git a/lua/gopher/struct_tags.lua b/lua/gopher/struct_tags.lua index d31ce4b..afd4f87 100644 --- a/lua/gopher/struct_tags.lua +++ b/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 @@ local function modify(...) -- stylua: ignore local cmd_args = { + "-transform", c.gotag.transform, "-format", "json", "-file", fpath, "-w" @@ -38,7 +39,7 @@ local function modify(...) 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