refactor: unite struct_tags util with main logic

This commit is contained in:
Oleksandr Smirnov 2025-10-29 17:11:54 +02:00
parent a67bf39c06
commit bef7b88379
No known key found for this signature in database
3 changed files with 54 additions and 53 deletions

View file

@ -1,43 +0,0 @@
local u = require "gopher._utils"
---@param option string
local function option_to_tag(option)
return option:match "^(.-)="
end
---@param args string[]
local function unwrap_if_needed(args)
if #args == 1 then
return vim.split(args[1], ",")
end
return args
end
local struct_tags = {}
---@class gopher.StructTagsArgs
---@field tags string
---@field options string
---@param args string[]
---@return gopher.StructTagsArgs
function struct_tags.parse_args(args)
args = unwrap_if_needed(args)
local tags, options = {}, {}
for _, v in pairs(args) do
if string.find(v, "=") then
table.insert(options, v)
table.insert(tags, option_to_tag(v))
else
table.insert(tags, v)
end
end
return {
tags = table.concat(u.list_unique(tags), ","),
options = table.concat(u.list_unique(options), ","),
}
end
return struct_tags