nvimdotfiles/lua/myworkflow/autocommands.lua

37 lines
877 B
Lua
Raw Normal View History

2024-01-16 15:33:32 +00:00
local autoformat_group = vim.api.nvim_create_augroup("autoformat", {})
vim.api.nvim_create_autocmd('BufWritePre', {
2024-01-16 15:33:32 +00:00
group = autoformat_group,
callback = function()
vim.lsp.buf.format { async = false }
end
})
local gotests = require("myworkflow.go-tests")
local atgroup = vim.api.nvim_create_augroup("autotest", {})
vim.api.nvim_create_autocmd('BufWritePost',
{
group = atgroup,
pattern = { "*.go" },
callback = function()
gotests.goRunTests()
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()
end
end, 500)
end
})