Add log to file. Fix gotest_fun

pull/21/head
ray-x 3 years ago
parent 6d41723098
commit 1bdf18bfc2

@ -15,16 +15,27 @@ function go.setup(cfg)
vim.cmd('command! Gofmt lua require("go.format").gofmt()')
vim.cmd('command! Goimport lua require("go.format").goimport()')
local cmds = vim.api.nvim_get_commands({})
if cmds["GoBuild"] == nil then vim.cmd([[command GoBuild :setl makeprg=go\ build | :Gmake]]) end
if cmds["GoGenerate"] == nil then vim.cmd([[command GoGenerate :setl makeprg=go\ generate | :Gmake]]) end
if cmds["GoRun"] == nil then vim.cmd([[command GoRun :setl makeprg=go\ run | :Gmake]]) end
if cmds["GoTestFunc"] == nil then vim.cmd([[command GoTestFunc :Gmake -run ..]]) end
if cmds["GoTest"] == nil then vim.cmd([[command GoTest :setl makeprg=go\ test\ ./... | :Gmake]]) end
if cmds["GoTestCompile"] == nil then vim.cmd([[command GoTestCompile :setl makeprg=go\ build | :Gmake]]) end
if cmds["GoBuild"] == nil then
vim.cmd([[command GoBuild :setl makeprg=go\ build | :Gmake]])
end
if cmds["GoGenerate"] == nil then
vim.cmd([[command GoGenerate :setl makeprg=go\ generate | :Gmake]])
end
if cmds["GoRun"] == nil then
vim.cmd([[command GoRun :setl makeprg=go\ run | :Gmake]])
end
if cmds["GoTestFunc"] == nil then
vim.cmd([[command GoTestFunc :lua require('go.gotest').test_fun()]])
end
if cmds["GoTest"] == nil then
vim.cmd([[command GoTest :setl makeprg=go\ test\ -v\ ./... | :Gmake]])
end
if cmds["GoTestCompile"] == nil then
vim.cmd([[command GoTestCompile :setl makeprg=go\ build | :Gmake]])
end
vim.cmd([[command! GoAddTest lua require("go.gotests").fun_test()]])
vim.cmd([[command! GoAddExpTest lua require("go.gotests").exported_test()]])

@ -1,5 +1,4 @@
-- https://phelipetls.github.io/posts/async-make-in-nvim-with-lua/
local M = {}
function M.make()
@ -23,7 +22,9 @@ function M.make()
vim.cmd([[setl errorformat+=%-G#\ %.%#,%f:%l:%c:\\?\ %m]])
end
if not makeprg then return end
if not makeprg then
return
end
local cmd = vim.fn.expandcmd(makeprg)
@ -42,21 +43,19 @@ function M.make()
})
vim.api.nvim_command("doautocmd QuickFixCmdPost")
end
if #lines > 1 then
vim.cmd("copen")
end
end
local job_id =
vim.fn.jobstart(
cmd,
{
on_stderr = on_event,
on_stdout = on_event,
on_exit = on_event,
stdout_buffered = true,
stderr_buffered = true,
}
)
local job_id = vim.fn.jobstart(cmd, {
on_stderr = on_event,
on_stdout = on_event,
on_exit = on_event,
stdout_buffered = true,
stderr_buffered = true
})
end
return M

@ -0,0 +1,21 @@
local M = {}
local utils = require("go.utils")
M.test_fun = function(args)
local cwd = vim.fn.getcwd(0)
local row, col = unpack(vim.api.nvim_win_get_cursor(0))
row, col = row + 1, col + 1
local ns = require("go.ts.go").get_func_method_node_at_pos(row, col)
if ns == nil or ns == {} then
return
end
utils.log("parnode" .. vim.inspect(ns))
local cmd = [[setl makeprg=go\ test\ -v\ -run\ ^]] .. ns.name
.. [[ | lua require"go.asyncmake".make()]]
utils.log("test cmd", cmd)
vim.cmd(cmd)
end
return M

@ -13,21 +13,21 @@ end
util.copy_array = function(from, to)
for i = 1, #from do
to[i] = from[i]
to[i] = from[i]
end
end
util.deepcopy = function (orig)
util.deepcopy = function(orig)
local orig_type = type(orig)
local copy
if orig_type == 'table' then
copy = {}
for orig_key, orig_value in next, orig, nil do
copy[util.deepcopy(orig_key)] = util.deepcopy(orig_value)
end
setmetatable(copy, util.deepcopy(getmetatable(orig)))
copy = {}
for orig_key, orig_value in next, orig, nil do
copy[util.deepcopy(orig_key)] = util.deepcopy(orig_value)
end
setmetatable(copy, util.deepcopy(getmetatable(orig)))
else -- number, string, boolean, etc
copy = orig
copy = orig
end
return copy
end
@ -47,8 +47,27 @@ util.handle_job_data = function(data)
end
util.log = function(...)
if vim.g.go_nvim_verbose then
print(...)
local arg = {...}
local log_path = vim.g.go_nvim_log_path or "/tmp/gonvim.log"
if vim.g.go_nvim_debug == true then
local str = ""
for i, v in ipairs(arg) do
if type(v) == "table" then
str = str .. " |" .. tostring(i) .. ": " .. vim.inspect(v) .. "\n"
else
str = str .. " |" .. tostring(i) .. ": " .. tostring(v)
end
end
if #str > 2 then
if log_path ~= nil and #log_path > 3 then
local f = io.open(log_path, "a+")
io.output(f)
io.write(str .. "\n")
io.close(f)
else
print(str .. "\n")
end
end
end
end

Loading…
Cancel
Save