diff --git a/lua/go/asyncmake.lua b/lua/go/asyncmake.lua index 7d590be..b9e4196 100644 --- a/lua/go/asyncmake.lua +++ b/lua/go/asyncmake.lua @@ -10,6 +10,7 @@ function M.make(...) local bufnr = vim.api.nvim_win_get_buf(winnr) local makeprg = vim.api.nvim_buf_get_option(bufnr, "makeprg") + log(makeprg, args) local indent = "%\\%( %\\)" if not makeprg then log("makeprog not setup") @@ -17,7 +18,7 @@ function M.make(...) end local efm = [[%-G#\ %.%#]] - if makeprg:find("go build") then + if makeprg:find("go build") then vim.cmd([[setl errorformat=%-G#\ %.%#]]) -- if makeprg:find("go build") then efm = efm .. [[,%-G%.%#panic:\ %m]] @@ -39,22 +40,23 @@ function M.make(...) if util.file_exists(cfg) then makeprg = makeprg .. [[\ -c\ ]] .. cfg - vim.api.nvim_buf_set_option(bufnr, "makeprg", makeprg) + -- vim.api.nvim_buf_set_option(bufnr, "makeprg", makeprg) end end if makeprg:find("go run") then - log("go run") if args == nil or #args == 0 then makeprg = makeprg .. " ." - vim.api.nvim_buf_set_option(bufnr, "makeprg", makeprg) + -- vim.api.nvim_buf_set_option(bufnr, "makeprg", makeprg) end efm = efm .. [[,%A%\\t%#%f:%l\ +0x%[0-9A-Fa-f]%\\+]] + + log("go run", makeprg) end if makeprg:find("go vet") then if args == nil or #args == 0 then makeprg = makeprg .. " ." - vim.api.nvim_buf_set_option(bufnr, "makeprg", makeprg) + -- vim.api.nvim_buf_set_option(bufnr, "makeprg", makeprg) end efm = efm .. [[,%-Gexit\ status\ %\\d%\\+]] end @@ -65,21 +67,14 @@ function M.make(...) -- efm = efm .. [[,]] .. require("go.gotest").efm() end - local arg = " " - for _, v in pairs(args or {}) do - arg = arg .. " " .. v - end - - if #arg > 0 then - makeprg = makeprg .. arg + local cmd = vim.fn.split(makeprg, " ") - vim.api.nvim_buf_set_option(bufnr, "makeprg", makeprg) + if args and #args > 0 then + cmd = vim.list_extend(cmd, args) + -- vim.api.nvim_buf_set_option(bufnr, "makeprg", makeprg) end - -- vim.cmd([[make %:r]]) - local cmd = vim.fn.expandcmd(makeprg) - - log(cmd, efm) + log(cmd, efm, arg) local function on_event(job_id, data, event) log(event, data) if event == "stdout" then @@ -121,11 +116,15 @@ function M.make(...) }) end vim.api.nvim_command("doautocmd QuickFixCmdPost") + + log(lines) + log("err", errorlines) + vim.cmd("botright copen") + if type(cmd) == "table" then + cmd = table.concat(cmd, " ") + end + print(cmd .. " finished") end - log(lines) - log("err", errorlines) - vim.cmd("botright copen") - print(cmd .. " finished") end local job_id = vim.fn.jobstart(cmd, { diff --git a/lua/go/ginkgo.lua b/lua/go/ginkgo.lua index 8cb363b..8a15411 100644 --- a/lua/go/ginkgo.lua +++ b/lua/go/ginkgo.lua @@ -17,7 +17,7 @@ local function get_build_tags(args) return "" end - return [[-tags\ ]] .. table.concat(tags, ",") .. [[\ ]] + return [[-tags\ ]] .. table.concat(tags, ",") end local function find_describe(lines) @@ -48,10 +48,11 @@ end -- Run with ginkgo Description M.test_fun = function(...) - - local args = {...} + local args = { ... } log(args) - local fpath = vim.fn.expand('%:p:h') + local fpath = vim.fn.expand("%:p:h") + + local row, col = unpack(vim.api.nvim_win_get_cursor(0)) row, col = row, col + 1 @@ -67,30 +68,31 @@ M.test_fun = function(...) log("failed to find test function, test file instead") return M.test_file(args) end - local test_runner = 'ginkgo' + local test_runner = "ginkgo" require("go.install").install(test_runner) + local cmd = { test_runner, [[ --focus=']] .. describe .. [[']], get_build_tags(args), fpath } + log(cmd) if _GO_NVIM_CFG.run_in_floaterm then - local cmd = test_runner .. [[ --focus=']] .. describe .. [[']] .. get_build_tags(args) .. [[ ]] .. fpath - log(cmd) - local term = require('go.term').run - term({cmd = cmd, autoclose = false}) + local term = require("go.term").run + term({ cmd = cmd, autoclose = false }) return end - local cmd = [[setl makeprg=]] .. test_runner .. [[\ --focus=']] .. describe .. [[']] .. get_build_tags(args) .. [[\ ]] - .. fpath .. [[ | lua require"go.asyncmake".make()]] - utils.log("test cmd", cmd) + local cmd = [[setl makeprg=]] .. test_runner vim.cmd(cmd) + + local args = { [[ --focus=']] .. describe .. [[']], get_build_tags(args), fpath } + require("go.asyncmake").make(unpack(args)) + utils.log("test cmd", cmd) return true end M.test_file = function(...) - - local args = {...} + local args = { ... } log(args) -- require sed - local fpath = vim.fn.expand('%:p:h') - local fname = vim.fn.expand('%:p') + local fpath = vim.fn.expand("%:p:h") + local fname = vim.fn.expand("%:p") log(fpath, fname) @@ -98,23 +100,29 @@ M.test_file = function(...) fname = "." .. fname:sub(#workfolder + 1) log(workfolder, fname) - local test_runner = 'ginkgo' + local test_runner = "ginkgo" require("go.install").install(test_runner) + local cmd_args = { + [[--regexScansFilePath=true]], + get_build_tags(args), + [[ --focus ]], + fname, + fpath, + } + if _GO_NVIM_CFG.run_in_floaterm then - cmd = test_runner .. [[ --regexScansFilePath=true ]] .. get_build_tags(args) .. [[ --focus ]] .. fname .. " " - .. fpath - utils.log(cmd) - local term = require('go.term').run - term({cmd = cmd, autoclose = false}) + table.insert(cmd_args, 1, test_runner) + utils.log(args) + local term = require("go.term").run + term({ cmd = cmd_args, autoclose = false }) return end fname = utils.relative_to_cwd(fname) .. [[\ ]] - local cmd = [[setl makeprg=ginkgo\ ]] .. get_build_tags(args) .. [[\ --regexScansFilePath=true\ --focus\ ]] .. fname - .. fpath .. [[| lua require"go.asyncmake".make()]] - utils.log("test cmd", cmd) - vim.cmd(cmd) + vim.cmd("setl makeprg=ginkgo") + utils.log("test cmd", cmd_args) + require("go.asyncmake").make(unpack(cmd_args)) end return M