Run tests and add diag on startup (when opening a folder with go.mod)
This commit is contained in:
parent
05f7d4a1fe
commit
3f4d2dcbb7
@ -15,7 +15,24 @@ vim.api.nvim_create_autocmd('BufWritePost',
|
||||
pattern = { "*.go" },
|
||||
callback = function()
|
||||
gotests.goRunTests()
|
||||
gotests.goSetMarks()
|
||||
gotests.goSetAllMarks()
|
||||
end
|
||||
}
|
||||
)
|
||||
|
||||
vim.api.nvim_create_autocmd('VimEnter', {
|
||||
pattern = { "*" },
|
||||
group = atgroup,
|
||||
nested = true,
|
||||
callback = function()
|
||||
-- we have to defer the autocommand, because otherwise treesitter
|
||||
-- will not highlight syntax (all code is plain white)
|
||||
vim.defer_fn(function()
|
||||
local gomod_exists = vim.fn.filereadable("go.mod")
|
||||
if gomod_exists ~= 0 then
|
||||
gotests.goRunTests()
|
||||
gotests.goSetAllMarks()
|
||||
end
|
||||
end, 500)
|
||||
end
|
||||
})
|
||||
|
@ -49,11 +49,11 @@ vim.api.nvim_create_user_command('GoTest', function()
|
||||
end, {})
|
||||
|
||||
vim.api.nvim_create_user_command('GoPrintResults', function()
|
||||
M.goPrintResults()
|
||||
print(vim.inspect(M.results))
|
||||
end, {})
|
||||
|
||||
vim.api.nvim_create_user_command('GoSetTestMarks', function()
|
||||
M.goSetMarks()
|
||||
M.goSetAllMarks()
|
||||
end, {})
|
||||
|
||||
vim.api.nvim_create_user_command('GoClearResults', function()
|
||||
@ -97,13 +97,26 @@ function M.goRunTests()
|
||||
vim.fn.jobwait({ id })
|
||||
end
|
||||
|
||||
function M.goPrintResults()
|
||||
print(vim.inspect(M.results))
|
||||
function M.goSetAllMarks()
|
||||
local files = vim.fn.system({ "find", "-type", "f", "-name", "*.go" })
|
||||
|
||||
local sep = "\n"
|
||||
local filetable = {}
|
||||
for str in string.gmatch(files, "([^" .. sep .. "]+)") do
|
||||
table.insert(filetable, str)
|
||||
end
|
||||
|
||||
for _, file in ipairs(filetable) do
|
||||
vim.fn.bufadd(file)
|
||||
vim.fn.bufload(file)
|
||||
local bufno = vim.fn.bufnr(file)
|
||||
M.goSetMarks(bufno)
|
||||
end
|
||||
end
|
||||
|
||||
function M.goSetMarks()
|
||||
local currbuf = vim.api.nvim_get_current_buf()
|
||||
function M.goSetMarks(currbuf)
|
||||
vim.api.nvim_buf_clear_namespace(currbuf, ns, 0, -1)
|
||||
vim.diagnostic.set(ns, currbuf, {}, {})
|
||||
local text = {}
|
||||
local failed = {}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user