From 0916cb3da1c8c4c5f693f0ea8185043e2344121e Mon Sep 17 00:00:00 2001 From: ray-x Date: Tue, 10 May 2022 11:03:15 +1000 Subject: [PATCH] bugfix for releative path for `GoTest -c` --- lua/go.lua | 2 +- lua/go/alt_getopt.lua | 1 + lua/go/gotest.lua | 12 ++++++------ lua/go/health.lua | 6 ++++++ lua/go/utils.lua | 5 +++-- 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/lua/go.lua b/lua/go.lua index 11dc134..d08547e 100644 --- a/lua/go.lua +++ b/lua/go.lua @@ -132,7 +132,7 @@ function go.setup(cfg) -- e.g. GoTestFile unit vim.cmd([[command! -nargs=* GoTestFile lua require('go.gotest').test_file()]]) - vim.cmd([[command! -nargs=* GoTestPkg lua require('go.gotest').test_package()]]) + vim.cmd([[command! -nargs=* -complete=custom,v:lua.package.loaded.go.package_complete GoTestPkg lua require('go.gotest').test_package()]]) vim.cmd([[command! -nargs=* GoAddTest lua require("go.gotests").fun_test()]]) vim.cmd([[command! -nargs=* GoAddExpTest lua require("go.gotests").exported_test()]]) vim.cmd([[command! -nargs=* GoAddAllTest lua require("go.gotests").all_test()]]) diff --git a/lua/go/alt_getopt.lua b/lua/go/alt_getopt.lua index 8f4c4d1..35a2823 100644 --- a/lua/go/alt_getopt.lua +++ b/lua/go/alt_getopt.lua @@ -159,6 +159,7 @@ function test_arg(arg) local optarg local optind arg = arg or { "-t", "-r", "-c", "path1", "-g", "unit,integration", "path" } + -- arg = arg or { "-t", "-r", "-c", "-g", "unit,integration" } opts, optind, optarg, unparsed = alt_getopt.get_ordered_opts(arg, "cg:hvo:n:rS:st", long_opts) print("ordered opts") diff --git a/lua/go/gotest.lua b/lua/go/gotest.lua index 4be9526..4f6c990 100644 --- a/lua/go/gotest.lua +++ b/lua/go/gotest.lua @@ -78,13 +78,15 @@ local function run_test(path, args) local bench = false local optarg, optind, reminder = getopt.get_opts(args, short_opts, long_opts) if optarg["c"] then - path = "." .. sep .. vim.fn.expand("%:h") -- vim.fn.expand("%:p:h") can not resolve releative path + path = utils.rel_path() -- vim.fn.expand("%:p:h") can not resolve releative path compile = true end if optarg["b"] then bench = true end - + if next(reminder) then + path = reminder[1] + end local test_runner = _GO_NVIM_CFG.go if _GO_NVIM_CFG.test_runner ~= test_runner then test_runner = _GO_NVIM_CFG.test_runner @@ -175,10 +177,8 @@ M.test_package = function(...) local args = { ... } log(args) - local repath = utils.rel_path() or "" - + local repath = utils.rel_path() or "." local fpath = repath .. utils.sep() .. "..." - utils.log("fpath: " .. fpath) -- args[#args + 1] = fpath @@ -222,7 +222,7 @@ M.test_fun = function(...) end if _GO_NVIM_CFG.verbose_tests then - table.insert("-v") + table.insert(cmd, "-v") end if not empty(tags) then diff --git a/lua/go/health.lua b/lua/go/health.lua index b649d3a..a2da4dd 100644 --- a/lua/go/health.lua +++ b/lua/go/health.lua @@ -32,6 +32,12 @@ local function binary_check() if no_err then ok("All binaries installed") end + + if vim.fn.executable('sed') == 1 then + info("sed installed.") + else + warn("sed is not installed.") + end end local function plugin_check() diff --git a/lua/go/utils.lua b/lua/go/utils.lua index 524e5f7..1889f45 100644 --- a/lua/go/utils.lua +++ b/lua/go/utils.lua @@ -410,10 +410,11 @@ end function util.rel_path() local fpath = vim.fn.expand("%:p:h") + local workfolders = vim.lsp.buf.list_workspace_folders() - if workfolder ~= nil then - fpath = "." .. fpath:sub(#workfolder + 1) + if workfolders ~= nil and next(workfolders) then + fpath = "." .. fpath:sub(#workfolders[1] + 1) end return fpath end