56 lines
1.7 KiB
Lua
56 lines
1.7 KiB
Lua
local job_id, job_buffer
|
|
|
|
local function job_exit(jobId, exit_code, _)
|
|
job_id = nil
|
|
print("job done!")
|
|
end
|
|
|
|
local function has_buffer()
|
|
return job_buffer and vim.fn.buflisted(job_buffer) == 1
|
|
end
|
|
|
|
local function get_build_cmd()
|
|
for path, type in vim.fs.dir(vim.fn.getcwd(), nil)
|
|
do
|
|
if (path == "build.zig") then
|
|
return "zig build"
|
|
end
|
|
if (path == "build.bat" or path == "build.sh") then
|
|
if (vim.loop.os_uname().sysname == "Windows_NT") then
|
|
-- TODO(twig): if I move to llvm this should work, right now cl doesn't work because nvim spawns a command prompt that doesn't have vcvars in it (nor does it have my stuff)
|
|
return "build.bat"
|
|
else
|
|
-- TODO(twig): this is untested!
|
|
return "build.sh"
|
|
end
|
|
end
|
|
end
|
|
return ""
|
|
end
|
|
|
|
function save_all_and_build()
|
|
if job_id then
|
|
print("Job processing")
|
|
return
|
|
end
|
|
|
|
local opts = {}
|
|
vim.api.nvim_exec('wa', opts)
|
|
|
|
if not has_buffer() then
|
|
job_buffer = vim.api.nvim_create_buf(true, true)
|
|
end
|
|
local job_window = vim.fn.bufwinnr(job_buffer)
|
|
if job_window ~= -1 then
|
|
vim.cmd(job_window .. ' wincmd w')
|
|
else
|
|
vim.cmd('buffer ' .. job_buffer)
|
|
end
|
|
vim.api.nvim_buf_set_option(job_buffer, 'filetype', 'build')
|
|
vim.api.nvim_buf_set_option(job_buffer, 'modified', false)
|
|
-- THis looks at files in the cwd and decides if there is something to build (build.zig for zig, build.bat/.sh for c++)
|
|
local build_cmd = get_build_cmd()
|
|
job_id = vim.fn.termopen(build_cmd, {on_exit = job_exit})
|
|
vim.api.nvim_buf_set_name(job_buffer, '[build]')
|
|
end
|