* refactor(ts_utils): i dont know why event it was here * fix: typos * fix(struct_tags)!: remove statement that i used for debug * refactor(ts_util): start from scratch * refactor(struct_tags): use new ts_util * fixup! refactor(struct_tags): use new ts_util * test(struct_tags): add support for multiple structs * fix(gotests): use new api * fix(impl): refactor some logic, use new api * docs(ts): add an explanation * refactor(_utils.ts): all public methods are just adapters * fix(comment): now it works * fixup! refactor(_utils.ts): all public methods are just adapters * fixup! fixup! refactor(_utils.ts): all public methods are just adapters * test(comment): e2e * tests(comment): fix * refactor(utils.ts): fix, docs * test(comment): fix tests again * fix(tests/comments): well, now i fell stupid * refactor(ts): add assert just to be sure that all elements are in the result * fix(ts): type annotations * fix(ts): pass bufnr to vim.treesitter.get_node * chore(ci): disable nightly * chore(ci): reorganize
53 lines
1.1 KiB
Lua
53 lines
1.1 KiB
Lua
local r = require "gopher._utils.runner"
|
|
local c = require("gopher.config").commands
|
|
local u = require "gopher._utils"
|
|
local gocmd = {}
|
|
|
|
---@param args string[]
|
|
---@return string[]
|
|
local function if_get(args)
|
|
for i, arg in ipairs(args) do
|
|
local m = string.match(arg, "^https://(.*)$") or string.match(arg, "^http://(.*)$") or arg
|
|
table.remove(args, i)
|
|
table.insert(args, i, m)
|
|
end
|
|
return args
|
|
end
|
|
|
|
---@param args unknown[]
|
|
---@return string[]
|
|
local function if_generate(args)
|
|
if #args == 1 and args[1] == "%" then
|
|
args[1] = vim.fn.expand "%"
|
|
end
|
|
return args
|
|
end
|
|
|
|
---@param subcmd string
|
|
---@param args string[]
|
|
---@return string[]|nil
|
|
function gocmd.run(subcmd, args)
|
|
if #args == 0 then
|
|
error "please provide any arguments"
|
|
end
|
|
|
|
if subcmd == "get" then
|
|
args = if_get(args)
|
|
end
|
|
|
|
if subcmd == "generate" then
|
|
args = if_generate(args)
|
|
end
|
|
|
|
return r.sync(c.go, {
|
|
args = { subcmd, unpack(args) },
|
|
on_exit = function(data, status)
|
|
if status ~= 0 then
|
|
error("gocmd failed: " .. data)
|
|
end
|
|
u.notify(c.go .. " " .. subcmd .. " ran successful")
|
|
end,
|
|
})
|
|
end
|
|
|
|
return gocmd
|