refactor(struct_tags): refactor range logic
This commit is contained in:
parent
79562a4ffb
commit
0e279f3cd0
1 changed files with 8 additions and 14 deletions
|
|
@ -64,20 +64,14 @@ local function handle_tags(fpath, bufnr, range, user_args)
|
||||||
"-w",
|
"-w",
|
||||||
}
|
}
|
||||||
|
|
||||||
-- since `-strut` and `-line` cannot be combined together set set them only
|
-- `-struct` and `-line` cannot be combined, setting them separately
|
||||||
-- if user doesn't do ranges
|
if range or st.is_varstruct then
|
||||||
if range ~= nil then
|
|
||||||
table.insert(cmd, "-line")
|
table.insert(cmd, "-line")
|
||||||
table.insert(cmd, string.format("%d,%d", range.start, range.end_))
|
table.insert(cmd, string.format("%d,%d", (range or st).start, (range or st).end_))
|
||||||
else
|
|
||||||
if st.is_varstruct then
|
|
||||||
table.insert(cmd, "-line")
|
|
||||||
table.insert(cmd, string.format("%d,%d", st.start, st.end_))
|
|
||||||
else
|
else
|
||||||
table.insert(cmd, "-struct")
|
table.insert(cmd, "-struct")
|
||||||
table.insert(cmd, st.name)
|
table.insert(cmd, st.name)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
for _, v in ipairs(user_args) do
|
for _, v in ipairs(user_args) do
|
||||||
table.insert(cmd, v)
|
table.insert(cmd, v)
|
||||||
|
|
@ -111,7 +105,7 @@ end
|
||||||
---@param args string[]
|
---@param args string[]
|
||||||
---@return string
|
---@return string
|
||||||
---@dochide
|
---@dochide
|
||||||
local function handler_user_args(args)
|
local function handler_user_tags(args)
|
||||||
if #args == 0 then
|
if #args == 0 then
|
||||||
return c.gotag.default_tag
|
return c.gotag.default_tag
|
||||||
end
|
end
|
||||||
|
|
@ -128,7 +122,7 @@ function struct_tags.add(opts)
|
||||||
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_tags = handler_user_args(opts.tags)
|
local user_tags = handler_user_tags(opts.tags)
|
||||||
handle_tags(fpath, bufnr, opts.range, { "-add-tags", user_tags })
|
handle_tags(fpath, bufnr, opts.range, { "-add-tags", user_tags })
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -142,7 +136,7 @@ function struct_tags.remove(opts)
|
||||||
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_tags = handler_user_args(opts.tags)
|
local user_tags = handler_user_tags(opts.tags)
|
||||||
handle_tags(fpath, bufnr, opts.range, { "-remove-tags", user_tags })
|
handle_tags(fpath, bufnr, opts.range, { "-remove-tags", user_tags })
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue