chore(build): streaming stdout (#511)

Signed-off-by: Aaron Pham <contact@aarnphm.xyz>
This commit is contained in:
Aaron Pham 2024-09-04 00:21:41 -04:00 committed by GitHub
parent 1e43122cac
commit b48b6b7afd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 3 deletions

View File

@ -66,9 +66,24 @@ M.build = function(opts)
error("Unsupported operating system: " .. os_name, 2)
end
local job = vim.system(cmd, { text = true }):wait()
return vim.tbl_contains({ 0 }, job.code) and true or false
---@type integer
local code
vim.system(cmd, {
text = true,
stdout = function(_, data)
if data then vim.schedule(function() vim.api.nvim_echo({ { data, "Normal" } }, false, {}) end) end
end,
stderr = function(err, _)
if err then vim.schedule(function() vim.api.nvim_echo({ { err, "ErrorMsg" } }, false, {}) end) end
end,
}, function(obj)
if vim.tbl_contains({ 0 }, obj.code) then
code = obj.code
else
vim.api.nvim_echo({ { "Build failed with exit code: " .. obj.code, "ErrorMsg" } }, false, {})
end
end)
return code
end
---@param question? string

View File

@ -73,6 +73,7 @@ H.keymaps = function()
vim.keymap.set({ "n", "v" }, "<Plug>(AvanteAsk)", function() require("avante.api").ask() end, { noremap = true })
vim.keymap.set("v", "<Plug>(AvanteEdit)", function() require("avante.api").edit() end, { noremap = true })
vim.keymap.set("n", "<Plug>(AvanteRefresh)", function() require("avante.api").refresh() end, { noremap = true })
vim.keymap.set("n", "<Plug>(AvanteBuild)", function() require("avante.api").build() end, { noremap = true })
vim.keymap.set("n", "<Plug>(AvanteToggle)", function() M.toggle() end, { noremap = true })
vim.keymap.set("n", "<Plug>(AvanteToggleDebug)", function() M.toggle.debug() end)
vim.keymap.set("n", "<Plug>(AvanteToggleHint)", function() M.toggle.hint() end)