cli improvement for gomodifytags, gotest

pull/135/head
ray-x 2 years ago
parent ffd3b019a9
commit ccaed8c573

@ -16,7 +16,7 @@ local run = function(...)
return
end
-- log(data)
if #data > 0 then
if #data > 4 then
data = vim.list_slice(data, 4, #data)
local TextView = utils.load_plugin("guihua.lua", "guihua.textview")
if TextView then
@ -36,6 +36,8 @@ local run = function(...)
vim.cmd(cmd)
vim.cmd("e")
end
else
vim.notify("No result " .. vim.inspect(data))
end
end
return { run = run }

@ -359,11 +359,15 @@ M.run = function(...)
-- if breakpoint is not set add breakpoint at current pos
local pts = require("dap.breakpoints").get()
if #pts == 0 then
require("dap").toggle_breakpoint()
if utils.empty(pts) then
require("dap").set_breakpoint()
end
testfunc = require('go.gotest').get_test_func_name()
if testfunc then
optarg["t"] = true
end
if optarg["t"] then
dap_cfg.name = dap_cfg.name .. " test"
dap_cfg.mode = "test"

@ -60,7 +60,7 @@ M.get_build_tags = function(args)
if optarg["t"] then
table.insert(tags, optarg["t"])
end
if #tags > 0 then
if type(tags) == 'table' and #tags > 0 then
return "-tags=" .. table.concat(tags, ","), reminder
end
end
@ -128,7 +128,7 @@ local function run_test(path, args)
end
if not empty(tags) then
cmd = vim.list_extend(cmd, tags)
cmd = vim.list_extend(cmd, {tags})
end
if not empty(reminder) then
cmd = vim.list_extend(cmd, reminder)

@ -1,4 +1,5 @@
local utils = require("go.utils")
local log = utils.log
local tags = {}
-- support -add-tags, --add-options, -remove-tags, -remove-options, clear-tags, clear-options
@ -32,18 +33,27 @@ tags.modify = function(...)
table.insert(setup, "-struct")
table.insert(setup, struct_name)
end
if transform then
table.insert(setup, "-transform")
table.insert(setup, transform)
end
local arg = { ... }
local transflg = false
for _, v in ipairs(arg) do
table.insert(setup, v)
if v == "-transform" or v == "-t" then
transflg = true
end
end
if not transflg then
if transform then
table.insert(setup, "-transform")
table.insert(setup, transform)
end
end
if #arg == 1 and arg[1] ~= "-clear-tags" then
table.insert(setup, "json")
end
log(setup)
-- vim.notify(vim.inspect(setup), vim.lsp.log_levels.DEBUG)
vim.fn.jobstart(setup, {
on_stdout = function(_, data, _)
@ -68,15 +78,24 @@ tags.modify = function(...)
})
end
-- e.g {"json,xml", "-transform", "camelcase"}
tags.add = function(...)
local cmd = { "-add-tags" }
local arg = { ... }
if #arg == 0 then
arg = { "json" }
end
local tg = select(1, ...)
if tg == "-transform" then
table.insert(cmd, 'json')
end
for _, v in ipairs(arg) do
table.insert(cmd, v)
end
log(cmd)
tags.modify(unpack(cmd))
end

@ -336,7 +336,7 @@ function util.load_plugin(name, modulename)
if has then
return plugin
end
local pkg = packer_plugins or nil
local pkg = packer_plugins or nil
if pkg ~= nil then
-- packer installed
local has_packer = pcall(require, "packer")
@ -469,6 +469,9 @@ function util.empty(t)
if t == nil then
return true
end
if type(t) ~= "table" then
return false
end
return next(t) == nil
end
@ -540,7 +543,7 @@ function util.lines_from(file)
end
function util.list_directory()
return fn.map(fn.glob(fn.fnameescape("./") .. "/{,.}*/", 1, 1), 'fnamemodify(v:val, ":h:t")')
return fn.map(fn.glob(fn.fnameescape("./") .. "/{,.}*/", 1, 1), 'fnamemodify(v:val, ":h:t")')
end
function util.get_active_buf()

Loading…
Cancel
Save