diff --git a/lua/grug-far/actions/search.lua b/lua/grug-far/actions/search.lua index 19ed1974..23828725 100644 --- a/lua/grug-far/actions/search.lua +++ b/lua/grug-far/actions/search.lua @@ -2,12 +2,11 @@ local fetchResults = require('grug-far/rg/fetchResults') local renderResultsHeader = require('grug-far/render/resultsHeader') local resultsList = require('grug-far/render/resultsList') --- TODO (sbadragan): problem when you search if you go: -> ge -> g , it gets stuck --- TODO (sbadragan): show progress when searching, helps with big searches local function search(params) local buf = params.buf local context = params.context local state = context.state + local isFinished; if state.abortSearch then state.abortSearch(); @@ -22,13 +21,15 @@ local function search(params) state.actionMessage = nil renderResultsHeader(buf, context) resultsList.clear(buf, context) - P('starting search') end) - state.abortSearch = fetchResults({ + state.abortSearch, isFinished = fetchResults({ inputs = state.inputs, options = context.options, on_fetch_chunk = vim.schedule_wrap(function(data) + if isFinished() then + return + end state.status = 'progress' state.progressCount = state.progressCount + 1 state.stats = { @@ -40,12 +41,12 @@ local function search(params) resultsList.appendResultsChunk(buf, context, data) end), on_finish = vim.schedule_wrap(function(status, errorMessage) - P('finish search with status ' .. (status or 'nil')) state.status = status if status == 'error' then state.stats = nil resultsList.setError(buf, context, errorMessage) elseif status == nil then + -- was aborted state.stats = nil state.actionMessage = nil end diff --git a/lua/grug-far/opts.lua b/lua/grug-far/opts.lua index 34566690..b6d6bef8 100644 --- a/lua/grug-far/opts.lua +++ b/lua/grug-far/opts.lua @@ -81,7 +81,8 @@ M.defaultOptions = { search = "ex: foo foo([a-z0-9]*) fun\\(", replacement = "ex: bar ${1}_foo $$MY_ENV_VAR ", filesFilter = "ex: *.lua *.{css,js} **/docs/*.md", - flags = "ex: --help --hidden (-.) --ignore-case (-i) --multiline (-U) --fixed-strings (-F)", + flags = + "ex: --help --ignore-case (-i) --replace= (empty replace) --multiline (-U)", }, -- strings to auto-fill in each input area at start diff --git a/lua/grug-far/rg/fetchWithRg.lua b/lua/grug-far/rg/fetchWithRg.lua index f2f3632d..ba082c8c 100644 --- a/lua/grug-far/rg/fetchWithRg.lua +++ b/lua/grug-far/rg/fetchWithRg.lua @@ -11,12 +11,17 @@ local function fetchWithRg(params) local on_fetch_chunk = params.on_fetch_chunk local on_finish = params.on_finish local args = params.args - local isFinished = false + local finished = false local errorMessage = '' + local function isFinished() + return finished + end + if not args then + finished = true on_finish(nil, nil) - return + return nil, isFinished end local stdout = uv.new_pipe() @@ -31,11 +36,11 @@ local function fetchWithRg(params) code -- signal ) - if isFinished then + if finished then return end - isFinished = true + finished = true closeHandle(stdout) closeHandle(stderr) closeHandle(handle) @@ -49,15 +54,14 @@ local function fetchWithRg(params) end) local on_abort = function() - if isFinished then + if finished then return end - isFinished = true + finished = true closeHandle(stdout) closeHandle(stderr) closeHandle(handle) - P('terminating search') uv.kill(pid, uv.constants.SIGTERM) on_finish(nil, nil); @@ -65,7 +69,7 @@ local function fetchWithRg(params) local lastLine = '' uv.read_start(stdout, function(err, data) - if isFinished then + if finished then return end @@ -94,7 +98,7 @@ local function fetchWithRg(params) end) uv.read_start(stderr, function(err, data) - if isFinished then + if finished then return end @@ -108,7 +112,7 @@ local function fetchWithRg(params) end end) - return on_abort + return on_abort, isFinished end return fetchWithRg