parent
76e817b5e1
commit
f23cb97d1a
37 changed files with 188 additions and 472 deletions
|
|
@ -65,8 +65,8 @@ end
|
|||
|
||||
---@class gopher.TsResult
|
||||
---@field name string
|
||||
---@field start integer
|
||||
---@field end_ integer
|
||||
---@field start_line integer
|
||||
---@field end_line integer
|
||||
---@field is_varstruct boolean
|
||||
|
||||
---@param bufnr integer
|
||||
|
|
@ -95,8 +95,8 @@ local function do_stuff(bufnr, parent_type, query)
|
|||
assert(res.name ~= nil, "No capture name found")
|
||||
|
||||
local start_row, _, end_row, _ = parent_node:range()
|
||||
res["start"] = start_row + 1
|
||||
res["end_"] = end_row + 1
|
||||
res["start_line"] = start_row + 1
|
||||
res["end_line"] = end_row + 1
|
||||
|
||||
return res
|
||||
end
|
||||
|
|
|
|||
|
|
@ -109,4 +109,4 @@ setmetatable(config, {
|
|||
|
||||
---@dochide
|
||||
---@return gopher.Config
|
||||
return config --[[ @as gopher.Config ]]
|
||||
return config
|
||||
|
|
|
|||
|
|
@ -37,22 +37,11 @@ local u = require "gopher._utils"
|
|||
local log = require "gopher._utils.log"
|
||||
local struct_tags = {}
|
||||
|
||||
---@dochide
|
||||
---@class gopher.StructTagInput
|
||||
---@field tags string[] User provided tags
|
||||
---@field range? gopher.StructTagRange (optional)
|
||||
|
||||
---@dochide
|
||||
---@class gopher.StructTagRange
|
||||
---@field start number
|
||||
---@field end_ number
|
||||
|
||||
---@param fpath string
|
||||
---@param bufnr integer
|
||||
---@param range? gopher.StructTagRange
|
||||
---@param user_args string[]
|
||||
---@dochide
|
||||
local function handle_tags(fpath, bufnr, range, user_args)
|
||||
local function handle_tags(fpath, bufnr, user_args)
|
||||
local st = ts.get_struct_under_cursor(bufnr)
|
||||
|
||||
-- stylua: ignore
|
||||
|
|
@ -64,10 +53,9 @@ local function handle_tags(fpath, bufnr, range, user_args)
|
|||
"-w",
|
||||
}
|
||||
|
||||
-- `-struct` and `-line` cannot be combined, setting them separately
|
||||
if range or st.is_varstruct then
|
||||
if st.is_varstruct then
|
||||
table.insert(cmd, "-line")
|
||||
table.insert(cmd, string.format("%d,%d", (range or st).start, (range or st).end_))
|
||||
table.insert(cmd, string.format("%d,%d", st.start_line, st.end_line))
|
||||
else
|
||||
table.insert(cmd, "-struct")
|
||||
table.insert(cmd, st.name)
|
||||
|
|
@ -105,7 +93,7 @@ end
|
|||
---@param args string[]
|
||||
---@return string
|
||||
---@dochide
|
||||
local function handler_user_tags(args)
|
||||
local function handler_user_args(args)
|
||||
if #args == 0 then
|
||||
return c.gotag.default_tag
|
||||
end
|
||||
|
|
@ -114,30 +102,28 @@ end
|
|||
|
||||
-- Adds tags to a struct under the cursor
|
||||
-- See |gopher.nvim-struct-tags|
|
||||
---@param opts gopher.StructTagInput
|
||||
---@param ... string Tags to add to the struct fields. If not provided, it will use [config.gotag.default_tag]
|
||||
---@dochide
|
||||
function struct_tags.add(opts)
|
||||
log.debug("adding tags", opts)
|
||||
|
||||
function struct_tags.add(...)
|
||||
local args = { ... }
|
||||
local fpath = vim.fn.expand "%"
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
|
||||
local user_tags = handler_user_tags(opts.tags)
|
||||
handle_tags(fpath, bufnr, opts.range, { "-add-tags", user_tags })
|
||||
local user_tags = handler_user_args(args)
|
||||
handle_tags(fpath, bufnr, { "-add-tags", user_tags })
|
||||
end
|
||||
|
||||
-- Removes tags from a struct under the cursor
|
||||
-- See `:h gopher.nvim-struct-tags`
|
||||
---@dochide
|
||||
---@param opts gopher.StructTagInput
|
||||
function struct_tags.remove(opts)
|
||||
log.debug("removing tags", opts)
|
||||
|
||||
---@param ... string Tags to add to the struct fields. If not provided, it will use [config.gotag.default_tag]
|
||||
function struct_tags.remove(...)
|
||||
local args = { ... }
|
||||
local fpath = vim.fn.expand "%"
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
|
||||
local user_tags = handler_user_tags(opts.tags)
|
||||
handle_tags(fpath, bufnr, opts.range, { "-remove-tags", user_tags })
|
||||
local user_tags = handler_user_args(args)
|
||||
handle_tags(fpath, bufnr, { "-remove-tags", user_tags })
|
||||
end
|
||||
|
||||
-- Removes all tags from a struct under the cursor
|
||||
|
|
@ -146,7 +132,7 @@ end
|
|||
function struct_tags.clear()
|
||||
local fpath = vim.fn.expand "%"
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
handle_tags(fpath, bufnr, nil, { "-clear-tags" })
|
||||
handle_tags(fpath, bufnr, { "-clear-tags" })
|
||||
end
|
||||
|
||||
return struct_tags
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue