Skip to content

Commit

Permalink
fixing error when no matches
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan Badragan committed May 7, 2024
1 parent 1d39e09 commit 9749418
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
4 changes: 3 additions & 1 deletion lua/grug-far/actions/replace.lua
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,12 @@ local function replace(params)
end)

local reportError = function(errorMessage)
vim.api.nvim_buf_set_option(buf, 'modifiable', true)

state.status = 'error'
state.progressCount = nil
state.actionMessage = getActionMessage(errorMessage)
resultsList.appendError(buf, context, errorMessage)
resultsList.setError(buf, context, errorMessage)
renderResultsHeader(buf, context)
end

Expand Down
2 changes: 1 addition & 1 deletion lua/grug-far/actions/search.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ local function search(params)
state.progressCount = nil
if status == 'error' then
state.stats = nil
resultsList.appendError(buf, context, errorMessage)
resultsList.setError(buf, context, errorMessage)
end

renderResultsHeader(buf, context)
Expand Down
6 changes: 4 additions & 2 deletions lua/grug-far/render/resultsList.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ function M.appendResultsChunk(buf, context, data)
end
end

function M.appendError(buf, context, error)
function M.setError(buf, context, error)
M.clear(buf, context)

local startLine = context.state.headerRow + 1

local err_lines = vim.split(error, '\n')
local err_lines = vim.split((error and #error > 0) and error or 'Unexpected error!', '\n')
vim.api.nvim_buf_set_lines(buf, startLine, startLine, false, err_lines)

for i = startLine, startLine + #err_lines do
Expand Down
4 changes: 4 additions & 0 deletions lua/grug-far/rg/fetchWithRg.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ local function fetchWithRg(params)
stdout:close()
stderr:close()
handle:close()

if code > 0 and #errorMessage == 0 then
errorMessage = 'no matches'
end
local isSuccess = code == 0 and #errorMessage == 0
on_finish(isSuccess and 'success' or 'error', errorMessage);
end)
Expand Down

0 comments on commit 9749418

Please sign in to comment.