cli improvement for gomodifytags, gotest

This commit is contained in:
ray-x 2022-06-03 19:07:05 +10:00
parent ffd3b019a9
commit ccaed8c573
5 changed files with 39 additions and 11 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -336,7 +336,7 @@ function util.load_plugin(name, modulename)
if has then if has then
return plugin return plugin
end end
local pkg = packer_plugins or nil local pkg = packer_plugins or nil
if pkg ~= nil then if pkg ~= nil then
-- packer installed -- packer installed
local has_packer = pcall(require, "packer") local has_packer = pcall(require, "packer")
@ -469,6 +469,9 @@ function util.empty(t)
if t == nil then if t == nil then
return true return true
end end
if type(t) ~= "table" then
return false
end
return next(t) == nil return next(t) == nil
end end
@ -540,7 +543,7 @@ function util.lines_from(file)
end end
function util.list_directory() 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 end
function util.get_active_buf() function util.get_active_buf()