diff options
author | Jarek Kobus <[email protected]> | 2023-06-01 03:20:12 +0200 |
---|---|---|
committer | Jarek Kobus <[email protected]> | 2023-06-01 11:49:07 +0000 |
commit | d81d1bc14c08645749b0d5fda1675dd20a369ad2 (patch) | |
tree | 644f2495911eb8f7f2c90d3a90222d6959f82f3b /src/plugins/silversearcher/silversearcherparser.cpp | |
parent | 1afa720f2cfee575096fc7f6afc5a0760496675b (diff) |
SilverSearcher: Make the search cancellable
Especially when there are lot of files, and not too much results.
Change-Id: Id9e89c5d0d681e11dd8a9fb5c2373164dbeef3fd
Reviewed-by: Orgad Shaneh <[email protected]>
Diffstat (limited to 'src/plugins/silversearcher/silversearcherparser.cpp')
-rw-r--r-- | src/plugins/silversearcher/silversearcherparser.cpp | 36 |
1 files changed, 28 insertions, 8 deletions
diff --git a/src/plugins/silversearcher/silversearcherparser.cpp b/src/plugins/silversearcher/silversearcherparser.cpp index be4e9096c4c..9cdf5211a67 100644 --- a/src/plugins/silversearcher/silversearcherparser.cpp +++ b/src/plugins/silversearcher/silversearcherparser.cpp @@ -3,6 +3,8 @@ #include "silversearcherparser.h" +#include <QFuture> + using namespace Utils; namespace SilverSearcher { @@ -94,23 +96,28 @@ static bool parseLineHits(QStringView *remainingInput, QList<QPair<int, int>> *h return true; } -SearchResultItems parse(const QString &input, const std::optional<QRegularExpression> ®Exp) +void parse(QPromise<SearchResultItems> &promise, const QString &input, + ParserState *parserState, const std::optional<QRegularExpression> ®Exp) { + QTC_ASSERT(parserState, return); SearchResultItems items; QStringView remainingInput(input); while (true) { + if (promise.isCanceled()) + return; + if (remainingInput.isEmpty()) break; const QStringView filePathLine = nextLine(&remainingInput); - if (filePathLine.isEmpty()) - continue; - - if (!filePathLine.startsWith(':')) + if (filePathLine.isEmpty()) { + parserState->m_lastFilePath = {}; // Clear the parser state continue; + } - const FilePath filePath = FilePath::fromPathPart(filePathLine.mid(1)); + if (filePathLine.startsWith(':')) + parserState->m_lastFilePath = FilePath::fromPathPart(filePathLine.mid(1)); while (true) { QStringView hitLine = nextLine(&remainingInput); @@ -126,7 +133,7 @@ SearchResultItems parse(const QString &input, const std::optional<QRegularExpres break; SearchResultItem item; - item.setFilePath(filePath); + item.setFilePath(parserState->m_lastFilePath); item.setDisplayText(hitLine.toString()); item.setUseTextEditorFont(true); for (const QPair<int, int> &hit : hits) { @@ -138,7 +145,20 @@ SearchResultItems parse(const QString &input, const std::optional<QRegularExpres } } } - return items; + if (!items.isEmpty()) + promise.addResult(items); + + parserState->m_reportedResultsCount += items.count(); +} + +SearchResultItems parse(const QString &input, const std::optional<QRegularExpression> ®Exp) +{ + QPromise<SearchResultItems> promise; + promise.start(); + ParserState dummy; + SilverSearcher::parse(promise, input, &dummy, regExp); + promise.finish(); + return promise.future().resultCount() ? promise.future().result() : SearchResultItems(); } } // namespace SilverSearcher |