diff --git a/lua/grug-far/actions/search.lua b/lua/grug-far/actions/search.lua index a8194d35..41b00b44 100644 --- a/lua/grug-far/actions/search.lua +++ b/lua/grug-far/actions/search.lua @@ -75,7 +75,11 @@ local function search(params) else if errorMessage and #errorMessage > 0 then resultsList.appendWarning(buf, context, errorMessage) - state.actionMessage = ' warnings, see end of buffer!' + + local lastline = vim.api.nvim_buf_line_count(buf) + local winheight = vim.api.nvim_win_get_height(vim.fn.bufwinid(buf)) + state.actionMessage = lastline < winheight and ' warnings!' + or ' warnings, see end of buffer!' end resultsList.highlight(buf, context) end diff --git a/lua/grug-far/engine/fetchCommandOutput.lua b/lua/grug-far/engine/fetchCommandOutput.lua index 6f15c9d7..b76ab506 100644 --- a/lua/grug-far/engine/fetchCommandOutput.lua +++ b/lua/grug-far/engine/fetchCommandOutput.lua @@ -28,6 +28,7 @@ local function fetchCommandOutput(params) local stdout = uv.new_pipe() local stderr = uv.new_pipe() local lastLine = '' + local hadStdout = false local handle handle = uv.spawn(params.cmd_path, { @@ -46,14 +47,12 @@ local function fetchCommandOutput(params) utils.closeHandle(stderr) utils.closeHandle(handle) - local isSuccess = code == 0 - if not isSuccess then - -- finish immediately if error, so no more result updates are sent out to the consumer - finished = true - end - vim.schedule(function() finished = true + -- note: when no stdout, we report errors with a message as warnings (status = success) since + -- for example ripgrep can generate errors only for a particular file (like permission denied + -- but everything else succeeded + local isSuccess = code == 0 or (hadStdout and errorMessage and #errorMessage > 0) on_finish(isSuccess and 'success' or 'error', errorMessage) end) end) @@ -90,6 +89,8 @@ local function fetchCommandOutput(params) end if data then + hadStdout = true + -- large outputs can cause the last line to be truncated -- save it and prepend to next chunk local chunkData = lastLine .. data diff --git a/lua/grug-far/render/resultsList.lua b/lua/grug-far/render/resultsList.lua index 3cb2e99b..5d7574e5 100644 --- a/lua/grug-far/render/resultsList.lua +++ b/lua/grug-far/render/resultsList.lua @@ -229,7 +229,7 @@ function M.appendWarning(buf, context, warning) end local lastline = vim.api.nvim_buf_line_count(buf) - local warn_lines = vim.split('\n\n' .. warning, '\n') + local warn_lines = vim.split(warning, '\n') setBufLines(buf, lastline, lastline, false, warn_lines) for i = lastline, lastline + #warn_lines - 1 do