Skip to content

Commit

Permalink
Merge pull request #168 from dinvlad/master
Browse files Browse the repository at this point in the history
Print errors from Sed replace command
  • Loading branch information
EpsilonKu authored Sep 13, 2023
2 parents 657e012 + 53a33eb commit 97cfd1b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lua/spectre/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ M.run_replace = function(entries)
end
end,
on_error = function(result)
if type(result.value) == "string" then
for line in result.value:gmatch("[^\r\n]+") do
print(line)
end
end
if (result.ref) then
error_item = error_item + 1
local value = result.ref
Expand Down
1 change: 1 addition & 0 deletions lua/spectre/replace/base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ base.on_error = function(self, value, ref)
if value ~= 0 then
pcall(vim.schedule_wrap(function()
self.handler.on_error({
value = value,
ref = ref
})
end))
Expand Down
5 changes: 4 additions & 1 deletion lua/spectre/replace/sed.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ sed.replace = function(self, value)
cwd = value.cwd,
args = args,
on_stdout = function(_, v) end,
on_stderr = function(_, v) self:on_error(v, value) end,
on_stderr = function(_, v)
v = self.state.cmd .. ' "' .. table.concat(args, '" "') .. '"\n' .. v
self:on_error(v, value)
end,
on_exit = function(_, v) self:on_done(v, value) end
})
job:sync()
Expand Down

0 comments on commit 97cfd1b

Please sign in to comment.