feat(struct_tags): add support for working with multiple tags at the once

This commit is contained in:
Oleksandr Smirnov 2025-03-19 17:42:11 +02:00
parent 223fa76647
commit db44842565
No known key found for this signature in database

View file

@ -76,14 +76,12 @@ local function handle_tags(fpath, bufnr, user_args)
vim.cmd "write" vim.cmd "write"
end end
---@param args string[]
---@return string
local function handler_user_args(args) local function handler_user_args(args)
local res = {} local res = table.concat(args, ",")
if #args == 0 then if res == "" then
table.insert(res, c.gotag.default_tag) return c.gotag.default_tag
else
for _, v in ipairs(args) do
table.insert(res, v)
end
end end
return res return res
@ -96,10 +94,8 @@ function struct_tags.add(...)
local fpath = vim.fn.expand "%" local fpath = vim.fn.expand "%"
local bufnr = vim.api.nvim_get_current_buf() local bufnr = vim.api.nvim_get_current_buf()
local user_args = handler_user_args(args) local user_tags = handler_user_args(args)
table.insert(user_args, 1, "-add-tags") handle_tags(fpath, bufnr, { "-add-tags", user_tags })
handle_tags(fpath, bufnr, user_args)
end end
---Removes tags from a struct under the cursor ---Removes tags from a struct under the cursor
@ -109,10 +105,8 @@ function struct_tags.remove(...)
local fpath = vim.fn.expand "%" local fpath = vim.fn.expand "%"
local bufnr = vim.api.nvim_get_current_buf() local bufnr = vim.api.nvim_get_current_buf()
local user_args = handler_user_args(args) local user_tags = handler_user_args(args)
table.insert(user_args, 1, "-remove-tags") handle_tags(fpath, bufnr, { "-remove-tags", user_tags })
handle_tags(fpath, bufnr, user_args)
end end
---Removes all tags from a struct under the cursor ---Removes all tags from a struct under the cursor