feat(git): highlight only fatal/error lines in failure dump
This commit is contained in:
+28
-3
@@ -321,6 +321,32 @@ local function clean_progress_line(line)
|
||||
return ""
|
||||
end
|
||||
|
||||
---@param lines string[]
|
||||
---@param fallback string
|
||||
---@return [string, string?][]
|
||||
local function format_error_dump(lines, fallback)
|
||||
if #lines == 0 then
|
||||
return { { fallback, "ErrorMsg" } }
|
||||
end
|
||||
local chunks = {}
|
||||
local matched = false
|
||||
for i, line in ipairs(lines) do
|
||||
if i > 1 then
|
||||
table.insert(chunks, { "\n" })
|
||||
end
|
||||
if line:match("^fatal:") or line:match("^error:") then
|
||||
table.insert(chunks, { line, "ErrorMsg" })
|
||||
matched = true
|
||||
else
|
||||
table.insert(chunks, { line })
|
||||
end
|
||||
end
|
||||
if not matched then
|
||||
return { { table.concat(lines, "\n"), "ErrorMsg" } }
|
||||
end
|
||||
return chunks
|
||||
end
|
||||
|
||||
---@param r ow.Git.Repo
|
||||
---@param args string[]
|
||||
local function run_streaming(r, args)
|
||||
@@ -387,9 +413,8 @@ local function run_streaming(r, args)
|
||||
)
|
||||
else
|
||||
emit_progress(("exit %d"):format(code), "failed")
|
||||
local body = #accum > 0 and table.concat(accum, "\n")
|
||||
or ("%s failed: exit %d"):format(title, code)
|
||||
vim.api.nvim_echo({ { body, "ErrorMsg" } }, true, {})
|
||||
local fallback = ("%s failed: exit %d"):format(title, code)
|
||||
vim.api.nvim_echo(format_error_dump(accum, fallback), true, {})
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user